将 MFMailComposeViewController 推送到导航堆栈上?不以模态方式呈现
我有一个表格视图,在其中一个单元格中,它显示“联系人”。选择此单元格后,我想推入 MFMailComposeViewController。
我似乎只能以模态方式呈现这个 MFMailComposeViewController 。这里有什么问题呢?
谢谢!
相关代码片段:
- (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];
}
我得到的错误是:“ * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“不支持推送导航控制器” *第一次抛出调用堆栈:“
所以看起来我已经有了一个navigationController,并且由于MFMailComposeViewController是UINavigationController的子类,所以我将一个navController推到另一个navController上?
我希望我的UI保持一致,所以我想将 MFMailComposeViewController 推送到导航堆栈上,而不是以模态方式呈现它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为
MFMailComposeViewController
不是UIViewController
的子类,而是UINavigationController
的子类。当您尝试将UINavigationController
或UINavigationController
的子类推送到现有堆栈时,UINavigationController
会引发异常。允许以模态方式呈现UINavigationController
。This is because
MFMailComposeViewController
isn't a subclass ofUIViewController
but ofUINavigationController
.UINavigationController
throws an exception when you're attempting to push aUINavigationController
or subclass ofUINavigationController
onto an existing stack. Presenting aUINavigationController
modally is permitted.根据苹果文档
因此您尝试做的事情应该在这两种情况下都有效。你看过日志吗?
我敢打赌你的navigationController是nil,因为这通常发生在你使用普通的UIViewController(没有嵌入
UINavigationController
中,但如果你实际上将你的模态视图呈现到navigationController上,它可能不会零。According to Apple documentation
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.