【问题标题】:uitabbarcontroller not showing on other uiviewcontrolleruitabbarcontroller 未显示在其他 uiviewcontroller 上
【发布时间】:2013-08-14 11:34:01
【问题描述】:

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

【问题讨论】:

  • 您想在标签栏控制器中添加导航控制器吗?你现在有相反的方式,所以新视图被推到标签栏上
  • @Leta0n haberler 是 uiviewcontroller

标签: iphone objective-c uinavigationcontroller uitabbarcontroller


【解决方案1】:

您将UITabBarController 作为UINavigationController 的rootViewController。并且UINavigationController 作为您的应用程序的根控制器。取而代之的是,您必须将 UITabBarController 设置为应用程序的根控制器,并在每个选项卡中添加 UINavigationController

检查this的答案。

【讨论】:

  • 感谢 Valantin 的回答。但是当我点击按钮时,我可以在哪里 pushViewController ?那么哪个导航控制器?
  • 你从你的一个标签里面的 navigationController 推送新的控制器。
【解决方案2】:

你应该尝试使用我的以下 sn-p

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 中两个选项卡的示例。您可以根据需要对其进行自定义。

享受编程!

【讨论】:

    【解决方案3】:

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

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

    例如,您有 loginScreen,而应用程序 lonch 并单击 login 按钮,您需要推送一个视图控制器,并且该视图控制器包含这些选项卡。

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多