【问题标题】:UINavigationController madness?UINavigationController 疯了吗?
【发布时间】:2012-12-27 14:14:28
【问题描述】:

我有两个问题我不明白,希望有人能提供帮助。

此代码不适用于从拆分视图控制器中获取我现有的 UINavigationController 层次结构并使用它来接管屏幕。我只是得到一个黑屏

UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"QuestionnaireViewController"];
[myself pushViewController:controller animated:YES];

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = myself;

但是,此代码确实有效。为什么我可以将 rootViewController 设置为新的 UINavigationController 而不是 self.navigationController?

UINavigationController *navController = [[UINavigationController alloc] init];
UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];
navController.viewControllers = myself.viewControllers;

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"QuestionnaireViewController"];
[navController pushViewController:controller animated:YES];

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = navController;

我的第二个问题是当用户“返回”时将导航控制器恢复到 splitViewController。我从经验中知道我可以为 detailView 分配一个新的 UINavigationController,但我无法分配 self.navigationController。

我认为这些问题是同一个问题。由于某种原因,新的 UINavigationController 与 UIView 的 navigationController 不同。为什么?

【问题讨论】:

    标签: ios


    【解决方案1】:

    干涉UIWindow 不是很安全。

    根据您要实现的目标,我可以想到 2 个相当简单的选项

    a) iOS 5.1+ 有一个选项可以显示/隐藏您拆分的 RootViewController 并使用滑动手势显示,然后使用它

    b) 创建您自己的模拟UISplitViewControllerUIViewController,并在需要时隐藏左侧部分

    【讨论】:

    • 我决定改用 modalViewController。如果需要,我可以将其嵌入到 NavigationController 中并轻松将其关闭以返回到之前的 splitViewController。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 2012-12-23
    相关资源
    最近更新 更多