• UITabBarController


    UITabBarController

    1.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    2. // Override point for customization after application launch.
    3. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    4. self.window.backgroundColor = [UIColor whiteColor];
    5. [self.window makeKeyAndVisible];
    6.
    7. ViewController *rootController = [[ViewController alloc] init];
    8. SecondViewController *second = [[SecondViewController alloc] init];
    9.
    10. UITabBarController *tabBarController = [[UITabBarController alloc] init];
    11. [tabBarController addChildViewController:rootController];
    12. [tabBarController addChildViewController:second];
    13.
    14.
    15. UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:nil
    16. image:[UIImage imageNamed:@"tabbar_sound_n"]
    17. selectedImage:[UIImage imageNamed:@"tabbar_sound_h"]];
    18.
    19. rootController.tabBarItem = item;
    20. rootController.tabBarItem.badgeValue = @"123";
    21.
    22. UITabBarItem *secondItem = [[UITabBarItem alloc] initWithTitle:nil
    23. image:[UIImage imageNamed:@"tabbar_me_n"]
    24. selectedImage:[UIImage imageNamed:@"tabbar_me_h"]];
    25.
    26. second.tabBarItem = secondItem;
    27.
    28.
    29. [self.window setRootViewController:tabBarController];
    30.
    31. return YES;
    32.}
    33.

    Alt text

    • 设置消息提醒个数即为:viewController.tabBarItem.badgeValue = @"123"
    • 有时我们需要将用户退出程序时所选中动视图控制器索引保存下来,以便下次用户重新进入程序时程序还是之前退出时的状态。
      tabBarController.delegate = self;
      并实现方法:
    1.-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    2.
    3. //用于保存用户偏好设置
    4. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    5. [userDefaults setInteger:tabBarController.selectedIndex forKey:@"selectedIndex"];
    6. [userDefaults synchronize];//强行立马写进文件(不写的话,那么就会是周期性的同步)
    7.}
     
  • 相关阅读:
    Eclipse 修改maven 仓储Repository位置
    使用Eclipse构建Maven的SpringMVC项目
    The word is not correctly spelled问题解决
    navicat for mysql 显示中文乱码解决办法
    Missing artifact net.sf.json-lib:json-lib:jar:2.2.3:compile
    ApacheTiles实战
    使用Apache Tiles3.x构建界面布局
    SpringMVC整合Tiles框架
    最近遇到的问题
    Unity3D流行的游戏开发人员构建高速检查站系统
  • 原文地址:https://www.cnblogs.com/buakaw/p/5194563.html
Copyright © 2020-2023  润新知