下面的代碼:
首先添加和導入信息框架:
#import <MessageUI/MessageUI.h>
然後標記你的自我作爲這樣
@interface MYViewController() <MFMailComposeViewControllerDelegate>
然後委託拉起作曲:
- (IBAction)emailButtonPressed:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
[composeViewController setMailComposeDelegate:self];
[composeViewController setToRecipients:@[@"[email protected]"]];
[composeViewController setSubject:@"example subject"];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}
然後辦理委託回調和罷免作曲家:使用actionSheet: clickedButtonAtIndex:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//Get the name of the current pressed button
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Your button title"]) {
[self btnContact];
}
}
調用此方法
- (void)btnContact{
// Email Subject
NSString *emailTitle = @"";
// Email Content
NSString *messageBody = @"";
// To address
NSString *toRecp = @"";
NSArray *toRecipents = [NSArray arrayWithObject:toRecp];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
你有什麼問題
在actionsheet? – 2014-12-04 11:54:29
UIViewController是否嵌入在UINavigationController中? – Anil 2014-12-04 11:56:10