简体   繁体   English

如何将子视图添加到UIViewController?

[英]How to add a subview to a UIViewController?

I am trying to add a UITabBarController to a UIViewController: 我试图将UITabBarController添加到UIViewController:

[self.view addSubView:tabBarController.view];

I get a warning: 我收到警告:

warning: 'UIView' may not respond to '-addSubView:'

How can I add a UITabBarController to my UIViewController? 如何将UITabBarController添加到UIViewController?

The specific warning you are getting is because you are spelling the method name wrong; 您收到的特定警告是因为您将方法名称拼写错误; try addSubview: instead of addSubView: . 尝试使用addSubview:而不是addSubView:

But, aside from that problem, you may still have difficulty getting the UITabBarController to work correctly in a subview, because it's not intended to be used that way. 但是,除了该问题之外,您可能仍然难以使UITabBarController在子视图中正常工作,因为它不是用于这种方式的。 The UITabBarController Class Reference says: UITabBarController类参考说:

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. 与其他视图控制器不同,不应将选项卡栏界面安装为另一个视图控制器的子级。

*emphasized text*replace with this---- *强调文字*替换为----

[self.view addSubview :obj.view]; [self.view addSubview :obj.view];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 UIViewController 中将 uitabbarcontroller 添加为子视图 - How to add uitabbarcontroller as a subview in UIViewController 如何将 UIViewController 的视图添加为子视图 - How to add an UIViewController's view as subview 如何将UIViewController添加为subview,使其在标签栏上方可见? - How to add UIViewController as subview , to be visible above tabbar? 如何在不使用IB的情况下将TableView Controller作为子视图添加到UIViewController? - How to add a TableView Controller as a subView to a UIViewController without using IB? 将子视图添加到UIImageView,它是IB中UIViewController的视图出口 - Add a subview to a UIImageView that is the view outlet of a UIViewController in IB 在uiviewcontroller中将uitableviewcontroller添加为子视图时出错 - error when add uitableviewcontroller as subview in uiviewcontroller 不使用IB将UIImageView添加为UIViewController的子视图 - Add a UIImageView as a subview of a UIViewController without using IB 如何在UIViewController中引用子视图的子节点 - How to refer to subview's children in a UIViewController 在情节提要中向从nib加载的自定义类UIViewController添加子视图 - Add a subview to a custom class UIViewController that loads from nib, in Storyboard 如何将videoPlayer添加为子视图? - How to add videoPlayer as an subview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM