user798719
user798719

Reputation: 9869

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.

Upvotes: 4

Views: 2701

Answers (2)

Mark Adams
Mark Adams

Reputation: 30846

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.

Upvotes: 3

rpechayr
rpechayr

Reputation: 1292

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.

Upvotes: 0

Related Questions