0

我的应用程序的第一页包含一个UITabBarControllertabBar。但是当我pushViewController到时UINavigationController,我UITabBarController的没有显示。

应用代理:

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。我怎么解决这个问题?

4

3 回答 3

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.

Check this answer.

于 2013-08-14T11:40:10.830 回答
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

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 :-

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.

- (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:-

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

}
于 2013-08-14T11:40:29.810 回答
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 中两个选项卡的示例。您可以根据需要对其进行自定义。

享受编程!

于 2013-08-14T11:47:19.603 回答