Tag Archives: segue

FAQ on iOS5 Storyboard

Designing iOS user interface with storyboard was introduced in iOS5. It helps to know of the following classes: UIStoryboardUIStoryboardPopoverSegueUIStoryboardSegue. The recommended practice is to have one storyboard for the entire application. I’ll address some of the common questions related to storyboard.

1. How do you pass data between two view controllers in storyboard?
You do that by overriding – [UIViewController prepareForSeque:sender:]. It is invoked on the source view controller and data can be passed back to source view controller by providing implementation of your own custom delegate. The source view controller can be accessed by [segue sourceViewController] and destination view controller can be accessed by [segue destinationViewController].

2. What is a static table view cell?
Table view cells that you can design inline and don’t need a data source. For static cells to work the view needs to be in a UITableViewController.

3. What is a dynamic table view cell?
The most common way of providing a table view cell. You can design it in the xib and it needs a table view data source. A very nice feature of storyboard.

4. How do you set which view controller is the first one to show?
Select a view controller and in Utilities pane go to Attributes Inspector, there check the property ‘Is Initial View Controller’.

5. How to add navigation controller to an existing view controller in storyboard?
From Menu you do: (Editor -> Embed In -> Navigation Controller)

6. How do you set delegate of destination view controller during transition?
Inside – [UIViewController prepareForSeque:sender:] you do [segue destinationViewController].delegate = self

7. How do you programmatically load a storyboard in AppDelegate or for that matter anywhere else?
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:nil];
self.window.rootViewController = (UINavigationController*)[storyboard instantiateInitialViewController];

(MainStoryboard is name of your storyboard file, replace it in case you use a different name)

See also -[UIStoryboard instantiateViewControllerWithIdentifier:]

8. How do you access a storyboard from within a view controller?
– [UIViewController storyboard]

9. How do you provide a custom segue?
By subclassing UIStoryboardSegue and overriding – [UIStoryboardSegue perform]. Inside method perform you can access source and destination view controllers by [self sourceViewController], [self destinationViewController]

10. How do you close a view controller opened as modal through segue transition?
-[UIViewController dismissModalViewControllerAnimated:]

11. How do you programmatically perform a segue transition?
The segue has to be specified by an identifier in the xib and then the source view controller can call
– [UIViewController performSegueWithIdentifier:sender:]

Feel free to leave a comment if you like any other questions answered.