如何让我的 iPhone 应用程序在启动时显示特定屏幕?
我有一个大应用程序,有很多屏幕,所有屏幕都按层次结构排列,顶部有一个 UITabBarController,下面有 UINavigationControllers,然后是下面的 UIView 控制器,也许在某个地方有一个模态控制器以进行良好的测量。
允许用户从列表中选择开始屏幕。选择后,下次启动应用程序时,它将从指定的屏幕启动,并且所有导航都将像他们自己导航到那里一样工作。
由于我无法子类化 UITabBarController 和 UINavigationController,因此我无法添加任何 ivars 来设置任何初始导航信息。
那么,在这些条件下设置层次结构并显示正确视图控制器的屏幕并快速完成的最佳方法是什么?
I have a big app with lots of screens, all arranged in a hierarchy, with a UITabBarController at the top, UINavigationControllers below that, and then UIView Controllers below those, maybe with a modal controller somewhere thrown in for good measure.
The user is allowed to pick a start screen from a list. Once selected, next time the app is started it will start from the specified screen and all the navigation will work as if they had navigated there themselves.
Since I can't subclass UITabBarController and UINavigationController, I can't add any ivars to set any initial navigation information.
So what is the best way get the hierarchy set up and the screen of the correct view controller showing under these conditions, and do it quickly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我是这样做的。
这两个方法都在 appDelegate 中,tabBarController 是一个实例变量。
Here's how I did it.
Both Methods are in the appDelegate and tabBarController is an instance variable.
我不确定你所描述的问题是什么。也就是说,为什么不
在应用程序退出时保存当前显示的视图(如果只有一种方式到达那里)或用户的导航路径(如果有多个路线),然后
重新创建视图层次结构,就像用户在 appDidFinishLaunching 中导航一样< /p>
... 中导航一样?
因此,例如,您可以在将控制器推入堆栈时保存控制器的类名称,然后在应用程序重新加载时创建单独的控制器类并将它们推入导航堆栈。对于选项卡控制器,您需要保存当时选择的选项卡的索引。
如果您的问题比这更复杂,也许可以对其进行编辑以解释您遇到困难的特定部分。
I'm not sure what the problem you're describing is. That is, why not just
Save either the current displayed-view (if there's only one way to get there) or the user's navigation path (if there are multiple routes) on app exit, then
Re-create the view hierarchy as if the user had navigated in your appDidFinishLaunching
...?
So, for example, you might save the class-names of the controllers as they're pushed into the stack then, when the app reloads, create the individual controller classes and push them onto the navigation stack. For tab controllers, you'll need to save the index of which tab was selected at the time.
If your problem/question is more complicated than this, perhaps edit it to explain the specific part where you're getting stuck.
我通过将一堆不同的值保存为用户默认值来做到这一点。但是,我的 applicationDidFinishLaunching 方法有点混乱,因为我使用一堆条件语句将视图控制器推入堆栈,决定选择哪些选项卡,决定是否显示模式视图等。
I do this by saving a bunch of different values as User Defaults. However, my applicationDidFinishLaunching method is a bit messy as I'm using a bunch of conditional statements to push View Controllers onto the stack, decide which tabs are selected, decide if a modal view is shown, etc.
保存用户每次想要加载的选项卡的索引,然后当应用程序启动时将 UITabBarController.selectedIndex 属性设置为此索引,然后您需要在 UITabBarController.selectedViewController 上调用 viewDidAppear。这应该会触发索引设置为可见。
Save the index of the tab the user wants to have loaded each time, and then when the app starts set the UITabBarController.selectedIndex property to this index and the then you will need to call viewDidAppear on the UITabBarController.selectedViewController. This should trigger the index to set to be visible.
您需要在退出之前查看 NSCoder 并保存视图层次结构。这样,要加载它们,您只需反序列化视图层次结构,状态就应该是相同的。
You will want to check out NSCoder and save the view hierarchy before exit. This way, to load them up, you just unserialize the view hierarchy and the state should be the same.