[英]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.