objective-c - 在 iOS 5 中关闭 UINavigationController

标签 objective-c ios5

我的问题似乎有点奇怪,我有一个自定义 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/

相关文章:

iphone - 将换行符附加到 NSString

ios - unwind segue 会弹出 View Controller 吗?

iOS:即使路径正确,Twitter Stream API 仍为 Expanded_URL 返回 Null?

ios - 使用 Objective-C 从不同的 ViewController 重新加载 TableView

iphone - iOS 5.0 AVAudioPlayer 加载音频剪辑时出错 : The operation couldn’t be completed.(OSStatus 错误 -50。)

objective-c - Segue 未出现在图像选择器之后

objective-c - IOS5编程和Objective C中的依赖注入(inject)

ios - 在应用程序启动时获取包文件引用/路径

ios - 如何从操作按钮调用 ShareKit 共享

ios - 在 UITableViewcell 的选定状态下更改图像