Sheehan Alam
Sheehan Alam

Reputation: 60919

How to add a subview to a UIViewController?

I am trying to add a UITabBarController to a 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?

Upvotes: 1

Views: 9889

Answers (2)

rahul gupta
rahul gupta

Reputation: 396

*emphasized text*replace with this----

[self.view addSubview:obj.view];

Upvotes: 2

David Gelhar
David Gelhar

Reputation: 27900

The specific warning you are getting is because you are spelling the method name wrong; try addSubview: instead of 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. The UITabBarController Class Reference says:

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.

Upvotes: 4

Related Questions