我的问题似乎有点奇怪,我有一个自定义 UITarBar
管理多个 UINavigationController
和一个 UIViewController
来呈现那些 NavController
模态地位于 UITabBar
按钮 touchUpInside
上,因此在 iOS 5 中,我的应用程序因 dismissModalViewControllerAnimated:
方法而崩溃... 如果将关闭方法更改为 iOS 5 上的新方法 (dismissViewControllerAnimated:completion:
),它不会关闭 NavController
。下面是一些关于我如何更改 Controller 的代码:
- (void) changeController
{
if ([self.generalViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
[self.generalViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
} else {
[self.generalViewController dismissModalViewControllerAnimated:NO];
}
[self.anotherNavController.view addSubview:customTabBar];
if ([self.generalViewController respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self.generalViewController presentViewController:anotherNavController animated:NO completion:nil];
} else {
[self.generalViewController presentModalViewController:anotherNavController animated:NO];
}
一切都在 AppDelegate
中进行管理。感谢您的建议。
编辑:我在这篇文章中找到了一些东西 dismissModalViewControllerAnimated: (and dismissViewControllerAnimated) crashing in iOS 5并做了他所做的(展示了第一个 viewControllerAnimated 动画),然后像我在 iOS 5 之前所做的一切检查新的 presentViewController 的选择器并且一切在模拟器上工作正常但在设备上不工作..
最佳答案
我不确定你的第一行,我认为第一行应该是:
if ([self.generalViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
[self.generalViewController dismissViewControllerAnimated:YES completion:nil];
您目前在上面的第二行中有一个无关的.presentingViewController。我在您上面的评论中看到您对此有一定的理由,但您是否尝试过其他选择?
无论如何,我在迁移到 iOS 5 时遇到了一个相关问题,并且发现解决方案是简单地发送关闭命令:
[self dismissViewControllerAnimated:YES];
我建议你试试。它对我有用,而且当我在那里运行代码时,它在 iOS 4.2 中也仍然有效......
编辑:更正,我正在更正的是 dismissModalViewControllerAnimated。然而,在那种情况下,我发现只是将消息发送给自己而不是针对 View Controller 是解决无法关闭 View 的问题,并且在 iOS 4 和 5 中工作......不会伤害到试试吧。
关于objective-c - 在 iOS 5 中关闭 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824086/