环境: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了