[英]issue with custom tab bar and navigation controller
好的,所以我有以下内容:
- (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。 当我单击任何选项卡时,它将在int retVal = UIApplicationMain(...)
崩溃(程序收到信号:EXC_BAD_ACCESS int retVal = UIApplicationMain(...)
更新:
如果您想调试它,我已经在git hub上载了示例代码,您可以在其中下载整个项目(我保证这是一个简单的测试项目)
您应该将控制器添加到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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.