ios - Objective-c 在应用程序启动后有条件地提供 ViewControllers

标签 ios objective-c uiviewcontroller

我有一个关于在应用程序启动时加载 View Controller 的问题。我想要一个条件来检查应用程序何时根据存储的核心数据值启动,如果为真,它将加载堆栈中第二个 View Controller 。如果为假,我想加载 Root View Controller 。无论条件结果如何,我都想始终保留 Root View Controller ,如果我的条件结果为真,我只想跳过加载此 View 并直接转到堆栈中的第二个 View 。我没有使用 Storyboard。以前有人做过这种性质的事情吗?
现在,话虽如此,这个逻辑流程是否是一个可以接受的实现解决方案。如果我这样尝试,提交过程中会不会有问题?

最佳答案

假设您有以下 View Controller :

UINavigationController *navigationController;
UIViewController *firstViewController;
UIViewController *secondViewController;

然后你可以这样写代码(编辑:根据下面的评论修改解决方案):

if (yourCondition)
    navigationController.viewControllers = @[ firstViewController, secondViewController ];
else
    navigationController.viewControllers = @[ secondViewController, firstViewController ];

关于ios - Objective-c 在应用程序启动后有条件地提供 ViewControllers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21785311/

相关文章:

cocoa - 查看文件所有者无法使用的 socket

ios - iOS、Core Data应用中的错误通信

ios - 将 Storyboard设置为起始文件而不是 xib

ios - iPhone SDK : How come the following code only animates first frame?

ios - 注册+确认密码iOS

swift - 使用 segue [Swift 3.0 Xcode] 通过多个 View Controller 传递数据

iOS:在编辑模式下更改约束

objective-c - NSPopUpButtonCell 子类以标准外观关闭动画

ios - 在复杂的 NSAttributedString 中插入字符串

ios - 如何使用 UIAppearance 设置 ViewController 的背景颜色