将TabBarController推送到视图

时间:2011-01-27 14:10:56

标签: objective-c ios view tabbarcontroller

如何将TabBarController推送到View?

该应用程序是基于视图的。在App中我有一个带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>.'

1 个答案:

答案 0 :(得分:2)

  

因为UITabBarController类继承自UIViewController类,所以选项卡栏控制器具有可通过view属性访问的自己的视图。 部署标签栏界面时,必须将此视图安装为窗口的根目录。与其他视图控制器不同,标签栏界面不应该作为另一个视图控制器的子项安装。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

这意味着什么,这不是“允许的”,Apple可能会或可能在将来拒绝您的申请。 UITabBarController旨在添加到应用程序委托中的根视图(窗口)。如果您希望稍后推送标签栏,则需要使用UIToolBar,例如: uisegmentedcontrol或工具栏按钮。

即使某些应用程序执行此操作(例如Wordpress应用程序),您稍后会发现在以模态方式呈现viewcontrollers时,您将在控制台中遇到一些问题。(将给出警告)。