按下按钮时,会显示MFMailComposeViewController
。
到目前为止我已经完成了。
我的问题是:
我该怎么做?
- (IBAction)questionButtonPressed:(id)sender {
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:@"Testing"];
// Optional Attachments
NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:@"albumart.png"]);
[email addAttachmentData:artwork mimeType:@"image/png" fileName:@"albumart.png"];
// Body
//[email setMessageBody:@"This is the body"];
// Present it
[self presentModalViewController:email animated:YES];
}
答案 0 :(得分:3)
是的,所有三种都是可能的,但是#2要么需要使用私有API,要么使用一些hackery。 我采用了子类化MFMailComposeViewController的方法,如下所示
// file: CustomMailComposeViewController.h
@interface CustomMailComposeViewController : MFMailComposeViewController {
}
@end
// file ustomMailComposeViewController.m
#import "CustomMailComposeViewController.h"
@implementation CustomMailComposeViewController
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Here we replace the cancel button with a back button (Question #3)
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)];
self.navigationBar.topItem.leftBarButtonItem = backButton;
[backButton release];
//Here we disallow the user to change to to: cc: bcc: and subject: feilds (Question #2)
//Warning: the xxxField methods are undocumented private methods.
UITableViewController *vc = [self.viewControllers objectAtIndex:0];
UITableView *tvv = [vc view];
[[tvv toField] setUserInteractionEnabled:NO];
[[tvv ccField] setUserInteractionEnabled:NO];
[[tvv bccField] setUserInteractionEnabled:NO];
[[tvv multiField] setUserInteractionEnabled:NO];
[[tvv subjectField] setUserInteractionEnabled:NO];
}
//This is the target for the back button, to immeditally dismiss the VC without an action sheet (#1)
-(void) backButtonPressed:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
@end
要在代码中使用,您需要更改:[[MFMailComposeViewController alloc] init]; to [[CustomMailComposeViewController alloc] init];
答案 1 :(得分:0)
抱歉