// 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];
}