简体   繁体   English

UI tabBar控制器

[英]UI tabBar Controller

i have created a single application and then created 2 tabs programmatically, then i have created 2 buttons tab 1 and tab 2 here is the code of .m file 我创建了一个应用程序,然后以编程方式创建了2个选项卡,然后创建了2个按钮,即选项卡1和选项卡2,这是.m文件的代码

(IBAction)tab1:(id)sender { self.tabBarController.selectedIndex=0; }
(IBAction)tab2:(id)sender { self.tabBarController.selectedIndex=1; }

here is the code of my appdelegate.m 这是我的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;
}

apparently there is no error in this code, if i set the tabbarcontroller as root it shows the tabs but when i want the viewcontroller to be root and buttons pointing to the tabs it doesnt work. 显然,此代码中没有错误,如果我将tabbarcontroller设置为root,它会显示选项卡,但是当我希望viewcontroller为root并且指向该选项卡的按钮不起作用时。

使用下面的代码隐藏tabbarviewcontroller的默认选项卡

[[self tabBarController] setTabBarHidden: YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM