Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 390
Sayali Avatar asked Nov 14 '11 13:11

Sayali


People also ask

How do I create a view controller from storyboard?

Step 1: Set a Storyboard ID In the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.

How do I change the initial view controller in storyboard?

Specifying the Initial View Controllerstoryboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller. Checking this box will identify the selected view controller as the initial entry point for the storyboard you're on.


1 Answers

,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.

like image 60
Scott Sherwood Avatar answered Oct 04 '22 02:10

Scott Sherwood