Iphone MFMailComposeViewController导航栏按钮已禁用

Iphone MFMailComposeViewController导航栏按钮已禁用,iphone,objective-c,button,sendmail,Iphone,Objective C,Button,Sendmail,我使用MFMailComposeViewController在我的应用程序中发送邮件。但当出现mail compose视图控制器时,所有导航按钮都被禁用(除了“选择邮件地址”屏幕中的“后退”按钮),我必须使用“主页”按钮退出应用程序。有人知道吗? 以下是屏幕截图: 代码: -(无效)共享电子邮件 { 如果([MFMailComposeViewController canSendMail]){ MFMailComposeViewController*mailViewController=[[

我使用MFMailComposeViewController在我的应用程序中发送邮件。但当出现mail compose视图控制器时,所有导航按钮都被禁用(除了“选择邮件地址”屏幕中的“后退”按钮),我必须使用“主页”按钮退出应用程序。有人知道吗? 以下是屏幕截图:


代码:

-(无效)共享电子邮件 { 如果([MFMailComposeViewController canSendMail]){ MFMailComposeViewController*mailViewController=[[MFMailComposeViewController alloc]init]; mailViewController.mailComposeDelegate=self; [mailViewController设置主题:@“测试主题”]; [mailViewController setMessageBody:@“邮件正文”isHTML:否]; NSData*imageData=[NSData dataWithContentsOfFile:photourl]; [mailViewController addAttachmentData:imageData mimeType:@“image/jpg”文件名:@“example_photo”]; [self-presentModalViewController:mailViewController动画:是]; }否则{ [[[UIAlertView alloc]initWithTitle:@“无法发送邮件”消息:@“设备无法在其当前状态下发送电子邮件”委托:自取消按钮:@“确定”其他按钮:无,无]显示]; } } 委托方法:

-(void)mailComposeController:(MFMailComposeViewController*)控制器未完成结果:(MFMailComposeResult)结果错误:(NSError*)错误 { 开关(结果) { 案例MFMailComposer结果已取消: //NSLog(@“结果:已取消”); 打破 案例MFMailComposer结果已保存: //NSLog(@“结果:已保存”); 打破 案例MFMailComposer结果已发送: { UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“结果”消息:@“邮件已成功发送”委托:nil CancelButtontile:@“确定”其他Buttontiles:nil,nil]; [警报显示]; } 打破 案例MFMailComposer结果失败: { UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“结果”消息:@“邮件发送失败”委托:nil CancelButtontile:@“确定”其他Buttontiles:nil,nil]; [警报显示]; } 打破 违约: //NSLog(@“结果:未发送”); 打破 } 如果(错误){ [[[UIAlertView alloc]initWithTitle:@“无法发送邮件”消息:[NSString stringWithFormat:@“错误:%@”,“错误用户信息]]委托:自取消按钮提示:@“确定”其他按钮提示:无,无]显示]; } [自我解散Modalviewcontrolleranimated:是]; }
在头文件中,我声明了implement MFMailComposeViewControllerDelegate。

在您的MFMailComposeViewController的委托中,您需要实现
didtfinishwithresult:
并从那里关闭模态视图控制器

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{ 
    // you can test the result of the mail sending here if you want

    [self dismissModalViewControllerAnimated:YES];
}
适用于swift 4.0+

func mailComposeController(controller: MFMailComposeViewController,
                           didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    // Check the result or perform other tasks.

    // Dismiss the mail compose view controller.
    controller.dismissViewControllerAnimated(true, completion: nil)
}

我也有同样的问题。我花了一段时间才弄明白这一点,但毫不奇怪,这归结于定制的维吾尔布托教派

我打赌在你的犹太教中有一种方法

-(void)setEnabled:(BOOL)enabled ;
实现如下所示:

-(void)setEnabled:(BOOL)enabled {
    if (self.customView) {
        if ([[self.customView.subviews objectAtIndex:0] isKindOfClass:[UIButton class]])         {
            ((UIButton*)[self.customView.subviews objectAtIndex:0]).enabled = enabled;
        }
    }
}

这是导致问题的原因,所以只要你注释掉这个方法,你的问题就应该消失。

我也有这个问题,但这是我的情况,因为我覆盖了
setNavigationBarHidden:animated:
来自
UINavigationController
,这是针对
CNContactViewController
中的一个bug而提出的。一种仍然包括变通方法并解决
MFMailComposeViewController
中问题的解决方案是使用方法swizzling,以便能够调用原始方法或重写的方法,根据当前
topViewController

的类别,您可以显示用于显示控制器的代码吗?奇怪,它看起来不错。这可能与您的电子邮件设置有关吗?在所有设备上都是这样吗?@mvds,在模拟器和设备上都是这样。苹果的示例项目运行良好。您是否意识到,每次提交一个
MFMailComposeViewController
实例时,都会泄漏该实例?如果第一个实例以某种方式持有某种类型的锁,从而阻止第二个实例获取锁,则可能会出现问题。添加一行
[mailer autorelease]某处,删除应用程序并重新安装。目前,我使用ARC支持来编译项目(无需自动释放、保留,…编码时),我认为这不是根本原因。但是,我将尝试只编译此文件,而不使用ARC支持。我实现了didFinishWithResult委托方法。耶!^^。你说得对!,非常感谢。我将重写这个方法。这个问题已经解决了。
-(void)setEnabled:(BOOL)enabled ;
-(void)setEnabled:(BOOL)enabled {
    if (self.customView) {
        if ([[self.customView.subviews objectAtIndex:0] isKindOfClass:[UIButton class]])         {
            ((UIButton*)[self.customView.subviews objectAtIndex:0]).enabled = enabled;
        }
    }
}