TabBar不应启用任何标签,直到用户点击任何一个标签页, 下面是我写入显示标签栏的代码,但默认情况下它显示的是第一个标签。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
PeopleViewController *peopleViewController = [[PeopleViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
[peopleViewController setTitle:@"People"];
EventsViewController *eventsViewController = [[EventsViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:eventsViewController];
[eventsViewController setTitle:@"Events"];
ActiveViewController *activeViewController = [[ActiveViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:activeViewController];
[activeViewController setTitle:@"Active"];
MoreViewController *moreViewController = [[MoreViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:moreViewController];
[moreViewController setTitle:@"More"];
NSArray *arrViewControllers = [[NSArray alloc] initWithObjects:nav1,nav2,nav3,nav4, nil];
[tabBarController setViewControllers:arrViewControllers];
[self.window addSubview:tabBarController.view];
return YES;
}
答案 0 :(得分:0)
为标签栏创建IBOutlet(例如theTabBar
)并使用以下代码:
[theTabBar setSelectedItem:nil];
答案 1 :(得分:0)
这是UITabBarController
的默认行为,默认选择第一个标签。
您可以选择在第一个实例中选择其他选项卡,但不能将选定的默认值更改为null。
[tabBarController setSelectedIndex:0];
默认选择索引为0,这是第一个选项卡,您可以根据需要将其更改为1,2,3。