可能重复:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tapped
我已根据Apple提供的代码示例在我的应用中实现了标准邮件功能。
我正在设置代理如下:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
我正在实施
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
点击发送按钮调用委托,一切正常。但是,点击“取消”按钮不会调用委托,它只会使视图变暗;应用程序挂在那里。
在这里阅读了类似的主题后,我一直认为视图可能因为某种原因而在屏幕外,这在我看来是无法理解的。请注意,视图是以编程方式创建的,并且未使用xib文件。
有什么想法或想法吗?
答案 0 :(得分:9)
您需要实施mailComposeController:didFinishWithResult:error
委托。并且您将关闭显示您的邮件视图的视图。如果您已将邮件视图作为modalView打开,则解除此问题的方法是 -
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
[self dismissModalViewControllerAnimated:YES];
return;
}
答案 1 :(得分:8)
对您有所帮助
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
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];
[alert release];
}
break;
case MFMailComposeResultFailed:
//NSLog(@"Result: failed");
break;
default:
//NSLog(@"Result: not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
答案 2 :(得分:0)
尝试添加简单的委托:
[picker setDelegate:self];