它一般用于在同一视图中各个子任务、 视图或的模型之间切换。
选项卡栏的示例如下所示:
重要的属性
示例代码和步骤
1. 创建一个新的项目,选择 Tabbed Application 替代视图应用程序 ,点击下一步, 输入项目名称和选择 create.
2. 这里默认创建两个视图控制器和标签栏添加到我们的应用程序。
3. AppDelegate.m didFinishLaunchingWithOptions方法如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = @[viewController1, viewController2]; self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; return YES; }
4. 两个视图控制器被用来分配作为选项卡栏控制器的视图控制器
5. 运行应用程序,得到如下结果: