objective-c - 将 TabBarController 推送到 View

标签 objective-c ios view tabbarcontroller

如何将 TabBarController 推送到 View ?

该应用程序是基于 View 的。在应用程序中,我有一个带有 TabBarController 的 XIB,我想将 TabBar 推到显示器上。我已经做了所有的事情,现在我不知道我做错了什么。

这是应该推送 TabBarController 的代码:

- (void)showTabBar {
TabBar *tbc = [[TabBar alloc] initWithNibName:@"TabBar" bundle:nil];
[self presentModalViewController:tbc animated:YES];
[tbc release];
}

此时 XIB 中有一个空 View 。所以当我运行这段代码时,显示器是白色的。还有 TabBarController,我想在显示器上看到它。

感谢您的帮助。


更新:

我应该说这是两个不同的类。函数“showTabBar”所在的类应该推送 TabBarController。第二类是TabBar。 TabBar 是 TabBarController 的委托(delegate)。

所以我修改了这样的答案,但我都试过了:

[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>.'

最佳答案

Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

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

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

即使某些应用程序这样做(例如 Wordpress 应用程序),您稍后会发现在以模态方式呈现 View Controller 时,您会在控制台中遇到一些问题。(将给出警告)。

关于objective-c - 将 TabBarController 推送到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4817367/

相关文章:

objective-c - NSString 、 EXC_BAD_ACCESS 和 stringByAppendingString

ios - 在 iOS7.1 中使用显示(推送)segue 不会出现导航栏

ios - Swift 中的 socket.io 出现意外的奇怪行为

Android - 如何找到具有共同属性的多个 View

objective-c - 动态 NSOutlineView 数据源

iphone - 如何在 iPhone sdk,objective-c 中获取 UIWebView 的内容高度?

ios - 在 iPhone 中使用 facebook 登录而不重定向到网络浏览器?

ios - 类型 'UIView' 的值没有成员 'image'

android - onMeasure 自定义 View 说明

django - 如何在 django 模板中使用 for 循环?