Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

guydor

macrumors member
Original poster
Mar 10, 2009
67
0
Hi,

I want to open the last tab the user left in UITabBarController.
I used this code but it didn't work:

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	tabBarController.selectedIndex =
    [[NSUserDefaults standardUserDefaults] integerForKey:@"lastOpenedTab"];
	
}


- (void)applicationWillTerminate:(UIApplication *)application {
	NSUserDefaults *lastTab = [NSUserDefaults standardUserDefaults];
	[lastTab setInteger:tabBarController.selectedIndex forKey:@"lastOpenedTab"];
	
}

I'd like to get help

Thanks!
 
Then start putting some effort in yourself: log the status of variables (are they nil), log the index you are getting back from the user defaults, check that the tab bar actually has that many tabs (for example if you add them dynamically you may have not done that yet).

Exhaust all the possibilities and you will find the answer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.