uitabbarcontroller没有显示在其他uiviewcontroller上

时间:2023-01-17 21:41:42

My app has a first page containing a UITabBarController and tabBar. But when I pushViewController to UINavigationController , my UITabBarController is not showing.

我的应用程序有一个包含UITabBarController和tabBar的第一页。但是当我将pushConController推送到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 have button and click events:

firstTab viewcontroller有按钮和点击事件:

-(void)btnClick:(id)sender
{
    [self.navigationController pushViewController:haberler animated:NO];
}

when I click UIViewController it is opening, but not showing UITabBarController. How can I solve this problem?

当我单击UIViewController时它正在打开,但没有显示UITabBarController。我怎么解决这个问题?

3 个解决方案

#1


1  

You have UITabBarController as rootViewController of your UINavigationController. And UINavigationController as root Controller of your app. Instead of that you have to set UITabBarController as root Controller of your App and add UINavigationController in each tab.

你有UITabBarController作为UINavigationController的rootViewController。和UINavigationController作为你的应用程序的根控制器。而不是必须将UITabBarController设置为应用程序的根控制器,并在每个选项卡中添加UINavigationController。

Check this answer.

检查这个答案。

#2


1  

You should try using my following snippet

您应该尝试使用我的以下代码段

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];

I've shown you the sample for two tabs inside tabbarcontroller. You can customise it as per your need.

我已经向你展示了tabbarcontroller中两个标签的示例。您可以根据需要自定义它。

Enjoy Programming!

#3


1  

First thing is that you need to create Array of Your All view-controller(Navigation Controller) like

首先,您需要创建所有视图控制器(导航控制器)的数组

self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController2,navigationController1,navigationController3,nil];

and

you need to set Winodw's Rootviewcontroller is [self.window setRootViewController:tabBarController]; not a Navigationcontroller

你需要设置Winodw的Rootviewcontroller是[self.window setRootViewController:tabBarController];不是Navigationcontroller

As par you Code example:-

作为代码示例: -

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; 

UPDATE:-

If you want to TabbarController adding at button Click for NextViewcontroller then you can do with something different way like Bellow :-

如果你想TabbarController添加按钮Click for NextViewcontroller然后你可以做一些不同的方式,如Bellow: -

For example you have loginScreen while app lonch and it login button click you need to push a view-controller and that View-controller contain those Tabbar.

例如,当app lonch和登录按钮单击时你有loginScreen你需要推送一个视图控制器,而View控制器包含那些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;
}

In loginViewcontroller LoginButton action:-

在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];

}

#1


1  

You have UITabBarController as rootViewController of your UINavigationController. And UINavigationController as root Controller of your app. Instead of that you have to set UITabBarController as root Controller of your App and add UINavigationController in each tab.

你有UITabBarController作为UINavigationController的rootViewController。和UINavigationController作为你的应用程序的根控制器。而不是必须将UITabBarController设置为应用程序的根控制器,并在每个选项卡中添加UINavigationController。

Check this answer.

检查这个答案。

#2


1  

You should try using my following snippet

您应该尝试使用我的以下代码段

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];

I've shown you the sample for two tabs inside tabbarcontroller. You can customise it as per your need.

我已经向你展示了tabbarcontroller中两个标签的示例。您可以根据需要自定义它。

Enjoy Programming!

#3


1  

First thing is that you need to create Array of Your All view-controller(Navigation Controller) like

首先,您需要创建所有视图控制器(导航控制器)的数组

self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController2,navigationController1,navigationController3,nil];

and

you need to set Winodw's Rootviewcontroller is [self.window setRootViewController:tabBarController]; not a Navigationcontroller

你需要设置Winodw的Rootviewcontroller是[self.window setRootViewController:tabBarController];不是Navigationcontroller

As par you Code example:-

作为代码示例: -

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; 

UPDATE:-

If you want to TabbarController adding at button Click for NextViewcontroller then you can do with something different way like Bellow :-

如果你想TabbarController添加按钮Click for NextViewcontroller然后你可以做一些不同的方式,如Bellow: -

For example you have loginScreen while app lonch and it login button click you need to push a view-controller and that View-controller contain those Tabbar.

例如,当app lonch和登录按钮单击时你有loginScreen你需要推送一个视图控制器,而View控制器包含那些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;
}

In loginViewcontroller LoginButton action:-

在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];

}