我创建了一个应用程序,然后以编程方式创建了2个选项卡,然后我创建了2个按钮选项卡1,这里的选项卡2是.m文件的代码
(IBAction)tab1:(id)sender { self.tabBarController.selectedIndex=0; }
(IBAction)tab2:(id)sender { self.tabBarController.selectedIndex=1; }
这是我appdelegate.m的代码
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.tabBarController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[firstViewController alloc] init];
UIViewController *viewController2 = [[secondViewController alloc] init];
self.tabBarController.viewControllers=[NSArray arrayWithObjects:viewController1,viewController2, nil];
//self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
return YES;
}
显然在这段代码中没有错误,如果我将tabbarcontroller设置为root,它会显示选项卡,但是当我希望viewcontroller为root时,指向选项卡的按钮不起作用。
答案 0 :(得分:0)
使用下面的代码
隐藏tabbarviewcontroller的默认tabbar[[self tabBarController] setTabBarHidden: YES];