我一直在关注如何以编程方式添加UITabBarController的不同教程.这很容易使用故事板来实现,但是因为我正在尝试以编程方式学习如何做事我无法做到这一点.目前我已经在didFinishLaunchingWithOptions中获得了这段代码.
tabBarController = [[UITabBarController alloc] init]; NSMutableArray *tabs = [[NSMutableArray alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[MenuViewController alloc] init]]; [tabBarController setViewControllers:tabs]; [tabs addobject:navController]; [self.window addSubview:tabBarController.view];
编辑代码:
tabBarController = [[UITabBarController alloc] init]; MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab]; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = @[navController]; [self.window setRootViewController:tabBarController]; [self.window makeKeyAndVisible];
这对于我的rootViewController调用MenuViewController没有任何意义.我怎样才能实现这一目标?
解决方法
用于5选项卡UITabbarcontroller的贝娄代码尝试使用以下波纹管代码: –
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:@"anasayfaViewController" bundle:nil]; UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab]; SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:@"SehirRehberiViewController" bundle:nil]; UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:sehirRehberi]; duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:@"duyuruViewController" bundle:nil]; UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:duyuru]; sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:@"sikayetViewController" bundle:nil]; UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:sikayet]; digerViewController *diger = [[digerViewController alloc] initWithNibName:@"digerViewController" bundle:nil]; UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:diger]; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = @[navigationController1,navigationController2,navigationController3,navigationController4,navigationController5]; [self.window setRootViewController:tabBarController]; [self.window makeKeyAndVisible];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。