UITabBarController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
ViewController *rootController = [[ViewController alloc] init];
SecondViewController *second = [[SecondViewController alloc] init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController addChildViewController:rootController];
[tabBarController addChildViewController:second];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:@"tabbar_sound_n"]
selectedImage:[UIImage imageNamed:@"tabbar_sound_h"]];
rootController.tabBarItem = item;
rootController.tabBarItem.badgeValue = @"123";
UITabBarItem *secondItem = [[UITabBarItem alloc] initWithTitle:nil
image:[UIImage imageNamed:@"tabbar_me_n"]
selectedImage:[UIImage imageNamed:@"tabbar_me_h"]];
second.tabBarItem = secondItem;
[self.window setRootViewController:tabBarController];
return YES;
}
- 设置消息提醒个数即为:
viewController.tabBarItem.badgeValue = @"123"
- 有时我们需要将用户退出程序时所选中动视图控制器索引保存下来,以便下次用户重新进入程序时程序还是之前退出时的状态。
tabBarController.delegate = self;
并实现方法:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setInteger:tabBarController.selectedIndex forKey:@"selectedIndex"];
[userDefaults synchronize];
}