如何将 TabBarController 推送到视图?
该应用程序是基于视图的。在应用程序中,我有一个带有 TabBarController 的 XIB,我想将 TabBar 推到显示器上。我已经做了一切,现在我不知道我做错了什么。
这是应该推送 TabBarController 的代码:
- (void)showTabBar {
TabBar *tbc = [[TabBar alloc] initWithNibName:@"TabBar" bundle:nil];
[self presentModalViewController:tbc animated:YES];
[tbc release];
}
此时,XIB 中有一个空视图。所以当我运行这段代码时显示是白色的。还有我想在显示器上看到的 TabBarController。
谢谢你的帮助。
更新:
我应该说这是两个不同的类别。函数“showTabBar”所在的类应该推送TabBarController。第二类是TabBar。TabBar 是 TabBarController 的委托。
所以我修改了这样的答案,但我都尝试了:
[self presentModalViewController:tbc.tabBarController.view animated:YES];
错误现在看起来像这样:
Incompatible Objective-C types 'struct UIView *', expected 'struct UIViewController *' when passing argument 1 of 'presentModalViewController:animated:' from distinct Objective-C type
更新:
嘿,错误消失了。凉爽的。;)
但该应用程序正在终止。我以前见过这种行为,但我不知道该怎么做。调试器控制台这样说:
2011-01-27 15:49:32.629 Touch[3657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <StartUp: 0x9300f20>.'