在用户单击任何一个选项卡之前,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;
}发布于 2014-10-27 17:28:54
为选项卡栏创建一个IBOutlet (例如theTabBar),并使用以下代码:
[theTabBar setSelectedItem:nil];
发布于 2014-10-27 17:48:15
这是UITabBarController的默认行为,默认情况下第一个选项卡处于选中状态。您可以选择在第一个实例中选择其他选项卡,但不能将默认选择项更改为空。
[tabBarController setSelectedIndex:0];默认选择的指标为0,这是第一个页签,您可以根据需要修改为1,2,3。
https://stackoverflow.com/questions/26584445
复制相似问题