代码中带有UINavigationController的UITabBar [英] UITabBar with UINavigationController in code

查看:33
本文介绍了代码中带有UINavigationController的UITabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个带有5个调用UIViews屏幕的UITabBar.该部分工作正常,但我想在其中几个中放入一个UINavigationController.我找到了一些可以正常工作的教程,但所有教程都在IB中实现了,如果可能的话,我想避免这种情况.

I've currently got a UITabBar with 5 screens calling UIViews. That part works fine but I want to put in a UINavigationController in a couple of them. I have found a few tutorials that work fine but all of them implement it in IB and I want to avoid that if possible.

我不知道在哪里实现UINavigationController,我应该在应用委托中使用UITabBar来实现它,并从UIView调用导航控制器,还是应该在UIView类中创建它?

I'm lost as to where to implement the UINavigationController, should I do it in the App Delegate with the UITabBar and call the navigation controller from the UIView or should I create it in the UIView class?

我尝试了8种不同的方法,但最终都会导致导航栏不起作用,根本没有导航栏或应用崩溃.

I've tried about 8 different ways and always ends up with either the Navbar not working, no nav bar at all or the app crashing.

当前,我像这样创建标签栏:

Currently I create the tab bar like this:

tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:@"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];

在initWithNibName中,我有这个:

And in the initWithNibName I have this:

self.title = @"Screen A";
self.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];

推荐答案

好,这样做吧...

Ok, do it like this...


    tabBarController = [[UITabBarController alloc] init];    
searchTableViewController = [[SearchTableViewController alloc] init];
    UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];                                                              

searchMapViewController = [[SearchMapViewController alloc] init];   
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];                                                    


tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil]; 

这篇关于代码中带有UINavigationController的UITabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆