当前位置: 代码迷 >> Iphone >> UITabBar没显示出来
  详细解决方案

UITabBar没显示出来

热度:92   发布时间:2016-04-25 06:15:00.0
UITabBar没有显示出来
环境:xcode4.0,Interface Builder
目的:我想不在MainWindow.xib里创建UITabBarController,改在其他的xib里
步骤: 
1. 创建一个纯正Window Based项目

2. 在xxxAppDelegate.h里增加一个viewcontroller属性(MainWindow.xib的东西我没修改)

3. 添加一个customTab.xib

4. 指定customTab.xib的File's Owner为 xxxAppDelegate

5. 在customTab.xib里,从library拖出来一个Tab Bar Controller

6. 在customTab.xib里,从library拖出来一个Object,custom class指向xxxAppDelegate

7. 关联Tab Bar Controller到Object(即xxxAppDelegate)的viewcontroller

启动项目,我发现UITabBar完全没显示出来。请问我哪个步骤出错了
------最佳解决方案--------------------
升级xcode吧,现在都用storyboard了
------其他解决方案--------------------
因为默认的window.rootViewController 还是指向的viewController属性。你所设置的那些都没用。
方法也不只是唯一通过nib文件来实现,你可以用代码来写

NSMutableArray *controllers=[NSMutableArray array];

FirstViewController *firstVC=[[FirstViewController alloc] init];
[controllers addObject:firstVC];
[firstVC release];

SecondViewController *secondVC=[[SecondViewController alloc] init];
[controllers addObject:secondVC];
[secondVC release];

.......
//创建UITabBarController
UITabBarController *tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:controllers];

self.window.rootViewController=tabBarController;
[tabBarController release];



------其他解决方案--------------------
可以试试storyboard了
------其他解决方案--------------------
我google好一阵,最后发现确实没法直接通过IB就显示/启动出非MainWindows.xib的UITabBarController,我把总结放在
http://www.cocoachina.com/bbs/read.php?tid=125671 了。