是非常可能的,
这个问题您有是要添加的tabBarController“到视图”的方式。我能够复制你的崩溃错误,就像你说没有给出有用的警告。
这是你是如何做的(我的例子是在didFinishLaunching中的appDelegate)
不正确的方法
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIViewController *vc = [[UIViewController alloc] init];
[vc.view setFrame:self.window.frame];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSMutableArray* controllers = [[NSMutableArray alloc] init];
for (int i=0; i<10; i++) {
UIViewController * vc1 = [[UIViewController alloc] init];
vc1.title = [NSString stringWithFormat:@"%d", i];
[controllers addObject:vc1];
}
[tabBarController setViewControllers:controllers];
self.window.rootViewController = vc;
[vc.view addSubview:tabBarController.view];
return YES;
正确的方法是设置tabBarController作为Windows RootViewController的而不是将tabBarControllers视图作为子视图添加到其他视图。
正确的方法(也didFinishLaunching中的appDelegate)
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NSMutableArray* controllers = [[NSMutableArray alloc] init];
for (int i=0; i<10; i++) {
UIViewController * vc1 = [[UIViewController alloc] init];
vc1.title = [NSString stringWithFormat:@"%d", i];
[controllers addObject:vc1];
}
[tabBarController setViewControllers:controllers];
self.window.rootViewController = tabBarController;
return YES;
希望这将你关在正确的轨道上。这里带走的消息是你不应该试图将viewControllers视图添加为其他viewControllers视图的子视图。
谢谢!它解决了崩溃!现在我的观点全是黑色的......我要解决它!非常感谢! –
很高兴我能帮上忙 – anders