我使用MFMailComposeViewController在我的应用程序中发送邮件。但是,当目前的邮件撰写视图控制器时,所有的导航按钮都被禁用(除了选择邮件地址屏幕中的后退按钮),我必须使用主页按钮退出应用程序。有没有人有想法? 下面是截图: MFMailComposeViewController禁用导航栏按钮
代码:
- (void)shareVieEmail { if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; mailViewController.mailComposeDelegate = self; [mailViewController setSubject:@"Test subject"]; [mailViewController setMessageBody:@"Mail message body" isHTML:NO]; NSData *imageData = [NSData dataWithContentsOfFile:photourl]; [mailViewController addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example_photo"]; [self presentModalViewController:mailViewController animated:YES]; } else { [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:@"Device is unable to send email in its current state" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; } }
委托方法:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { switch (result) { case MFMailComposeResultCancelled: //NSLog(@"Result: canceled"); break; case MFMailComposeResultSaved: //NSLog(@"Result: saved"); break; case MFMailComposeResultSent: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } break; case MFMailComposeResultFailed: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } break; default: //NSLog(@"Result: not sent"); break; } if (error) { [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:[NSString stringWithFormat:@"ERROR:%@", [error userInfo]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; } [self dismissModalViewControllerAnimated:YES]; }
而且在头文件中,我宣布实施MFMailCompos eViewControllerDelegate。
可以显示用于显示控制器的代码吗? – mvds 2012-01-14 07:08:57
@mvds我发布了我的代码。 – youshunei 2012-01-14 16:34:51
奇怪,看起来不错。它可能与你的电子邮件设置有关吗?它在所有设备上都是这样吗? – mvds 2012-01-15 13:08:14