MFMailComposeViewController navigation bar buttons are disabled

删除回忆录丶 提交于 2019-12-06 06:24:08

I had exactly the same problem. and it took me a while to figure this out but no surprise it came down to customized UIBarButtonItem

I bet in your UIBarButtonItem.h there is a method

-(void)setEnabled:(BOOL)enabled ;

and the implementation looks like this:

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

and this is causing problem so as soon as you comment out this method your problem should go away.

newenglander

I also had this problem, but it my case it was because I had overridden setNavigationBarHidden:animated: from UINavigationController as proposed in this workaround for a bug in CNContactViewController. One solution that would still include the workaround and solve the problem in MFMailComposeViewController would be to use method swizzling to be able to call either the original method or the overridden one, depending on the class of the current topViewController.

jonkroll

In your MFMailComposeViewController's delegate you need to implement didFinishWithResult: and dismiss the modal view controller from there.

- (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];
}

For 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)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!