好的,我有以下内容:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController * tabBarController = [[MainViewController alloc] init];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[tabBarController release];
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
return YES;
}
这里,MainViewController只是UITabBarController的子类,而在MainViewController的viewDidLoad中我有:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
MapViewController * map = [[MapViewController alloc] init];
[localControllersArray addObject:map];
//[localNavigationController release];
[map release];
ListViewController * voteSpot = [[ListViewController alloc] initWithTabBar];
[localControllersArray addObject:voteSpot];
//[localNavigationController release];
[voteSpot release];
ProfileViewController * profile = [[ProfileViewController alloc] initWithTabBar];
[localControllersArray addObject:profile];
//[localNavigationController release];
[profile release];
self.viewControllers = localControllersArray;
[localControllersArray release];
}
现在我能看到的只是:
知道为什么是白屏吗?
这是我的initWithTabBar的一个例子:
-(id) initWithTabBar {
if ([self init]) {
self.navigationItem.title=@"Map";
}
return self;
}
暂时忽略底部标签栏(中间缺少一个),这正是我想要的。我感到困惑的是与每个标签相关联的viewController,它没有任何内容,而实际上MapViewController有一个MapView in它。当我点击任何标签时,它会在int retVal = UIApplicationMain(...)
更新:
如果你想调试它,我已经在git hub上传了一个示例代码,您可以在这里下载整个项目(我保证这是一个简单的测试项目)
答案 0 :(得分:0)
您应该将控制器添加到TabBarControllers viewControllers
属性。像这样:
self.viewControllers = [NSArray arrayWithObjects:map, voteSpot, profile, nil];
编辑:对不起,我没有看到你已经有了。但是,根据实际问题,上面的代码片段实际上可以解决您的问题。
一些事情:
编辑2: 在查看了您的项目之后,我能够通过将applicationDidFinishLaunchingWithOptions方法更改为以下内容来启动并运行并显示选项卡视图:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BaseViewController * tabBarController = [[BaseViewController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
//MapViewController * map = [[MapViewController alloc] init];
//UINavigationController* mapNavController = [[[UINavigationController alloc]
// initWithRootViewController:map] autorelease];
//[map release];
//[localControllersArray addObject:mapNavController];
ProfileViewController * profile = [[ProfileViewController alloc] init];
[localControllersArray addObject:profile];
[profile release];
tabBarController.viewControllers = localControllersArray;
[localControllersArray release];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
[tabBarController release];
return YES;
}