简体   繁体   中英

Pushing an MFMailComposeViewController onto the navigation stack? Not presented modally

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM