我使用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