Pushing an MFMailComposeViewController onto the navigation stack? Not presented modally

霸气de小男生 提交于 2019-12-04 03:55:38

问题


I have a table view, and in one of the cells, it says "contact". Upon selecting this cell, I'd like to push in a MFMailComposeViewController.

I can only seem to present this MFMailComposeViewController modally. What is the problem here?

Thanks!

Relevant code frag:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    //*works*//[self.navigationController presentModalViewController:controller animated:YES];
    //*broken*//[self.navigationController pushViewController:controller animated:YES];

}

The error that I get is: " * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported' * Call stack at first throw:"

So it looks like I have a navigationController already, and since MFMailComposeViewController is a subclass of UINavigationController, I'm pushing a navController onto another navController?

I want my UI to be consistent, so I want to push a MFMailComposeViewController onto the nav stack rather than present it modally.


回答1:


This is because MFMailComposeViewController isn't a subclass of UIViewController but of UINavigationController. UINavigationController throws an exception when you're attempting to push a UINavigationController or subclass of UINavigationController onto an existing stack. Presenting a UINavigationController modally is permitted.




回答2:


According to Apple documentation

To display the view managed by this view controller, you can use any of the standard techniques for displaying view controllers

So what you are trying to do is supposed to work in both cases. Did you have a look at the logs ?

I would have bet your navigationController is nil, because this typically happens when you are using a plain UIViewController (not embedded in a UINavigationController, but it you actually present your modal view onto the navigationController, it may not be nil.



来源:https://stackoverflow.com/questions/7937415/pushing-an-mfmailcomposeviewcontroller-onto-the-navigation-stack-not-presented

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