iOS Add a view in xib but i still need to use addView

86 Views Asked by At

I have a view where I added a view2 in xib (with interface builder), i joined everything with my viewClass. Everything is working.

But when I do in viewDidLoad :

view2 = [[[OtherViewController alloc]initWithNibName:@"OtherViewController" bundle:nil]view];

I still have my view but i don't have the outlets from OtherViewController view. I have to do :

[self.view addSubview:view2]; // It works, i see my outlets

Can someone tell me why ? And how can i do ? I need to add the OtherViewCOntroller view without using addSubview.

TY

1

There are 1 best solutions below

2
On

You can do this if you are using storyboard, there is a Container View that you can add as subview, and connect that container view to your OtherViewController by an EmbedSegue (if you are using iOS 6.0 or above). In this case you would not need any additional code to write.