UITabBarController无法加载“更多"消息. applicationDidFinishLaunching上的视图 [英] UITabBarController not loading "More" views at applicationDidFinishLaunching

查看:92
本文介绍了UITabBarController无法加载“更多"消息. applicationDidFinishLaunching上的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试恢复多选项卡iPhone应用程序的状态.有5个以上的标签,每个标签都有自己的导航控制器.在applicationDidFinishLaunching上,我确定哪个是用户位于的最后一个标签,并使用

I'm trying to restore the state of my multi-tabbed iPhone application. There are more than 5 tabs, each with it's own navigation controller. On applicationDidFinishLaunching, I determine which was the last tab the user was on and set it with

myTabController.selectedIndex = persistedTabIndex;

myTabController.selectedIndex = persistedTabIndex;

然后我在该选项卡的根视图控制器上调用一个函数以恢复自身.问题是,如果选项卡已移至更多"页面,则视图尚未加载,并且调用消失在NIL区域中.有没有一种方法可以强制有问题的视图控制器加载其视图?

I then call a function on that tab's root view controller to restore itself. The problem is, if the tab has been moved to the "More" page, the view has not been loaded and the call disappears into NIL land. Is there a way to force the view controller in question to load it's view?

在此先感谢您的考虑和答复.

Many thanks in advance for your consideration and responses.

推荐答案

我正在使用一些在网上找到的代码来保存上次加载的标签.在我的应用程序委托中:

I'm using some code I found on the web to save the last loaded tab. In my app delegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{   
    // .. my app set up is here

    // Select the tab that was selected on last shutdown
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger whichTab = [defaults integerForKey:kSelectedTabDefaultsKey];
    self.tabBarController.selectedIndex = whichTab;
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Save the current tab so the user can start up again in the same place.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger whichTab = self.tabBarController.selectedIndex;
    [defaults setInteger:whichTab forKey:kSelectedTabDefaultsKey];
}

以及我的界面文件中的定义:

and the definition in my interface file:

#define kSelectedTabDefaultsKey @"SelectedTab"

这是有效的,除非用户重新排列选项卡,在这种情况下,您必须更新选项卡的数组(索引将更改).

This works unless the user rearranges the tabs, in which case you have to update the array of tabs (the index will change).

这是我在其中找到代码的原始页面:

Here's the original page where I found the code:

http://iphonedevelopment.blogspot.com/2009/09/saving -tabs.html

我在选项卡式界面上使用此代码,该界面显示更多..."选项卡.当我在更多..."部分下的选项卡上退出时,当我重新启动应用程序时,界面会返回到该选项卡.该界面不会在更多..."表视图上重新启动,但是我不认为这是一个问题.

I'm using this code on a tabbed interface which shows the "More..." tab. When I quit on a tab under the "More..." part, the interface comes back to that tab when I restart the app. The interface won't restart on the "More..." table view, but I don't consider that a problem.

这篇关于UITabBarController无法加载“更多"消息. applicationDidFinishLaunching上的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆