uitabbarcontroller没有显示在其他uiviewcontroller上

时间:2013-08-14 11:34:01

标签: iphone objective-c uinavigationcontroller uitabbarcontroller

我的应用的首页包含UITabBarControllertabBar。 但是当我pushViewControllerUINavigationController时,我的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。我怎么解决这个问题?

3 个答案:

答案 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中两个标签的示例。您可以根据需要自定义它。

享受编程!