How to save the current element of the tab bar when the user shuts down and reloads into this element when restarting?

I want to save the current tab that the user is in when the user quits the application, so I can download the application with this tab highlighted when the user re-enters the application.

I assume that I use the following method in my application deletion to save the current tab

- (void)applicationWillTerminate:(UIApplication *)application

but how do I access the current tab - and what would be the best way to reload it?

+3
source share
3 answers

applicationWillTerminate selectedIndex tabbarcontroller .

  [[NSUserDefaults standardUserDefaults] setInteger:[tabBarController selectedIndex] forKey:@"tabBarIndex"];

NSDefaults .

    setIndex = [[NSUserDefaults standardUserDefaults] objectForKey:@"tabBarIndex"];
    [[NSUserDefaults standardUserDefaults] synchronize];

setIndex - NSUInteger. TabBarController viewDidLoad :

[tabBarController selectedIndex:setIndex];

, , .

,

+5

Jordan , , selectedIndex - , ; :

tabBarController.selectedIndex = setIndex;
0

UITabBarController , ; NSUserDefaults , , .

I'm intentionally vague here because the details of UITabBarController and NSUserDefaults are in the documentation and you need to learn to read before you ask others for help. All you need should be in your Xcode documentation browser or, if you haven't installed the documentation, at http://developer.apple.com .

-2
source

Source: https://habr.com/ru/post/1705504/


All Articles