Search code examples
ios5storyboard

How to create custom view controller container using storyboard in iOS 5


In iOS5 using storyboard feature I want to create a custom container which will have 2 ViewControllers embedded in it. For Example, embed Table view controller as well as a view controller both in one ViewController.

That is, one view controller will have 2 relationship:

  1. to table view controller
  2. to view controller which in turn will have 4 UIImage view Or UIButton in it

Is creating this type of relationship possible using storyboard's drag drop feature only & not programmatically?


Solution

  • ,You should only have one view controller to control the scene. However, this viewController might have two other view controllers that control particular subviews on your scene. To do this you create properties in your scene viewController, in your case one for your tableViewController and one for your view. I like to keep things together so I make both these viewControllers outlets and create them in interface builder. To create them in interface builder pull in an Object from the Object library and set its type to the relevant viewController. Hook it up to the appropriate outlet you just created in your scene's viewController - Note: this is important otherwise the viewController will be released if you are using ARC and crash your app. Then hook these viewControllers up to the view you want them to control and you are done.

    Alternatively you can instantiate and hop up your viewControllers in your scenes viewController should you prefer to do this.

    Hope this helps.

    Edit: On reflection this is not a good idea and actually goes against the HIG you should maintain only one ViewController for each screen of content and instead try to create a suitable view class and have the single view controller deal with the interactions between the various views.