Codesnipp.it Social Code Sharing

kinopyo

Autosave the last selected tab bar item.

by kinopyo on Nov 25, 2010

// I copied this from a book and I didn't actually test it. // Take it as a note. // in .h #define kSelectedTabDefaultsKey @"Selected Tab" // in .m #pragma mark - #pragma mark Tab Bar Delegate // UITabBar maintains an array of its items called items. - (void)tabBar:(UITabBar *)theTabBar didSelectItem:(UITabBarItem *)item { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUInteger tabIndex = [tabBar.items indexOfObject:item]; [defaults setInteger:tabIndex forKey:kSelectedTabDefaultsKey]; }

Can't see the comments? Please login first :)