objective c - Adding a UIViewController to a UIView -


I have ViewcontrollerA , a view created in storyboard is. In this view, I have UIView which I have added to the storyboard and make it an outlet named containerView .

I want to add some other viewControllerB (also created in storyboard ) in the container.

Tried it:

  // Add a new view from the storyboard in the container, in which the service view with ID UIViewController * sv = [self.storyboard instantiateViewControllerWithIdentifier: @ " ServiceView "]; [Self.containerView addSubview: sv.view];  

and crashed.

How can I do this?

Thank you.

This most likely crashed because sv is zero , although you should have posted that for the reason that the accident in your question if this is the reason, then perhaps it is possible because in your storyboard there is not a view controller with that storyboard identifier but even so That if you have decided it, then it's a hint to see the controller's prevention Way is not.

To add a view controller as a second view controller, you will have to use the added visual controller control API in iOS 5. Actually you can see the controller control without writing the code to the storyboard. Can also be used. From the Object Library, you can drag the "Container view", it will allow you to attach another view controller graphically to your storyboard.


Comments