UITabBarController not loading “More” views at applicationDidFinishLaunching

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 06:51:10

问题


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;

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.


回答1:


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.




回答2:


That's odd; if the navigation controller is in the tab controller's array, it should be getting its -loadView method called as usual when it's selected, regardless of whether it's in the main 4. You might try manually calling [thePersistedController loadView] after creating it but before telling the tab controller to select it.



来源:https://stackoverflow.com/questions/1402811/uitabbarcontroller-not-loading-more-views-at-applicationdidfinishlaunching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!