将key定义为宏
#define VC_Index_KEY @"kobe"
遵守<UITabBarControllerDelegate>代理。
// 取值
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger index = [[userDefaults objectForKey:VC_Index_KEY] integerValue];
self.selectedIndex = index;
#pragma mark - 标签栏的代理方法
// 选中,存储
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:[NSNumber numberWithInteger:index] forKey:VC_Index_KEY];
[userDefaults synchronize];
}