将 MFMailComposeViewController 推送到导航堆栈上?不以模态方式呈现

发布于 2024-12-12 09:47:44 字数 897 浏览 0 评论 0原文

我有一个表格视图,在其中一个单元格中,它显示“联系人”。选择此单元格后,我想推入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-12-19 09:47:44

这是因为 MFMailComposeViewController 不是 UIViewController 的子类,而是 UINavigationController 的子类。当您尝试将 UINavigationControllerUINavigationController 的子类推送到现有堆栈时,UINavigationController 会引发异常。允许以模态方式呈现 UINavigationController

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.

太傻旳人生 2024-12-19 09:47:44

根据苹果文档

要显示此视图控制器管理的视图,您可以使用任何显示视图控制器的标准技术

因此您尝试做的事情应该在这两种情况下都有效。你看过日志吗?

我敢打赌你的navigationController是nil,因为这通常发生在你使用普通的UIViewController(没有嵌入UINavigationController中,但如果你实际上将你的模态视图呈现到navigationController上,它可能不会零。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文