我的应用的首页包含UITabBarController
和tabBar
。
但是当我pushViewController
到UINavigationController
时,我的UITabBarController
没有显示。
的appdelegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:@"anasayfaViewController" bundle:nil];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:@"SehirRehberiViewController" bundle:nil];
duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:@"duyuruViewController" bundle:nil];
sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:@"sikayetViewController" bundle:nil];
digerViewController *diger = [[digerViewController alloc] initWithNibName:@"digerViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[firstTab,sehirRehberi,duyuru,sikayet,diger];
navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
self.window.rootViewController = self.navigationController;
// [self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
firstTab viewcontroller有按钮并单击事件:
-(void)btnClick:(id)sender
{
[self.navigationController pushViewController:haberler animated:NO];
}
当我点击UIViewController
时,它正在打开,但没有显示UITabBarController
。我怎么解决这个问题?
答案 0 :(得分:1)
您有UITabBarController
作为UINavigationController
的rootViewController。并UINavigationController
作为您应用的根控制器。相反,您必须将UITabBarController
设置为应用的根控制器,并在每个标签中添加UINavigationController
。
检查this回答。
答案 1 :(得分:1)
首先,您需要创建像所有视图控制器(导航控制器)的数组,如
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController2,navigationController1,navigationController3,nil];
和
你需要设置Winodw的Rootviewcontroller
[self.window setRootViewController:tabBarController];
不是导航控制器
与你的代码示例相同: -
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];
return YES;
<强>更新: - 强>
如果你想TabbarController
添加按钮Click for NextViewcontroller,那么你可以用不同的方式来做像Bellow: -
例如,您有应用程序lonch loginScreen 并且单击login
按钮,您需要推送视图控制器,并且该视图控制器包含那些Tabbar。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LoginViewcontroller *objLogin = [[LoginViewcontroller alloc] initWithNibName:@"LoginViewcontroller" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
在loginViewcontroller中的LoginButton操作: -
-(IBAction)LoginSuccess
{
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.navigationController pushViewController:self.tabBarController animated:YES];
}
答案 2 :(得分:1)
您应该尝试使用我的以下代码段
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:@"anasayfaViewController" bundle:nil];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstTab];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:@"SehirRehberiViewController" bundle:nil];
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:sehirRehberi];
// object for tabbarviewcontroller
self.tab.viewControllers = [NSArray arrayWithObjects:firstNav,secondNav,nil];
我已经向你展示了tabbarcontroller中两个标签的示例。您可以根据需要自定义它。
享受编程!