iOS 9 Storyboards – Everything You Need to Know .

Posted in: Blog

Storyboards have been an ultimate addition to the repertoire of iOS since iOS 5. Numerous upgrades and useful features have been made part of the Storyboards since then and it has become a useful tool for the iPhone developers. From unfurled segues to back navigation and referencing features, iOS 9 Storyboard has evolved a great deal from its predecessors. Storyboards in iOS 9 are now more user friendly and supportive.

Our iOS Developers have diagnosed and measured the performance of the Storyboards on the basis of which we shall share here some of the most intriguing facets you need to know about the iOS 9 Storyboards:

New Features in the iOS Storyboards:

In order to enhance the utility of the Storyboards, some important updates were required which are made part of it now.
These updated features are as listed below:

1. Xcode 7 for References:

In case you have used Storyboards for bigger projects, you must be aware of the fact that the Storyboards can go quite clumsy at times. There were lots of issues with the Storyboards like disarranged segue arrows, flustering outlook and no proper dimensions to work around. Another complain that used to appear was about the difficulty of working with multiple Storyboards through help of interface builder. In your apps, moving between different “View Controllers” of alternative storyboards demanded individual codes which made the process tedious and less effective.

This is no longer the case though and all these issues have been rectified in iOS 9 Storyboards. The “View Controller” can easily be controlled with the help of Storyboard references. You can move to a specific “View Controller” and work between multiple view controllers of different storyboards with the help of references.

We shall learn how it gets done in real-time with the help of Xcode7 Referencing:

From Xcode 7, create a new project, configure it with “TabBarBased” application & select language (Swift, Objective C) of your own choice. Now open up the “Main.storyboard” file by clicking it.
It will look like this:

Screen Shot 2015-11-04 at 7.16.37 PM

Here we consider the First Tab as a separate module and look to create a new storyboard with all of its related views.
Xcode 7 provides us with an option to do this in an easier way.
First Select all the scenes you want in different Storyboard. Then from Xcode Menu, select Editor & then choose to “Refactor to Storyboard”.
Like this:

new edit

After Saving, Xcode will create a new storyboard that includes the selected Scenes. And the first Scene will be the initial scene as you can see in the screen below:

new one

Now going back to Main.storyboard, you will see, it has become simpler.

perf

The selected scenes have been replaced by a Storyboard reference with the FirstTab (the name you have entered while re-factoring Storyboard).

Result:
As you have seen, the Storyboards references are a great way to visualize the scenes across the Storyboards.
A Storyboard reference will instantiate the initial scene of referenced Storyboard by default, but we can link to any scene in the storyboard that has a StoryboardID.

2. Segue Customization in Interface Builder:

There are two fundamental segue types and both can be customized in the latest version of the iOS Storyboards. These two types are:

• Standard Segues
• Adaptive Segues

Customization for Standard Segues:

Customizing standard segues with the help of Xcode has become stress-free. In Xcode 7 with iOS 9, you can select any standard segue type (e.g. Present Modally) and specify a subclass of UIStoryboardSegue. With the help of postulating subclass, the overall implementation of the Perform Method gets enhanced. In such a case the Segue object gets referenced and saved till the current view is presented.

Following is the summary of steps for customization of standard segues:

  • To present any custom animation with “Modal Segue”, assign a subclass of UIStoryboardSegue in interface builder and override the perform method. At this stage, the “Destination View Controller” gets instantiated but not presented to the screen yet. So, get the “destinationViewcontroller” and assign its transitionDelegate.
  • In the second step, call super.perform() method to start the modal presentation. Now the destinationViewController gets called for presentingViewController method. It consults with the transitioningDelegate to vend the animationController object (implementing UIViewControllerAnimatedTransitioning protocol) that actually drives the animation.
  • For dismissal, the viewController still has the transitionDelegate assigned to it. And it asks transitionDelegate for an animationController to drive the dismissal.

Important Point, to note here; if the segue object is not being held which is in turn holds the transitionDelegate object, we wouldn’t able to achieve the dismissal animation.

Customization for the Adaptive Segues:

  • First, assign a subclass of UIStoryboardSegue in interface builder. Then override the perform method and assign delegate (which implements the UIAdaptivePresentationControllerDelegate protocol) to presentation controller of “destinationViewcontroller”.
  • Secondly, call super.perform() method to start the modal presentation. Here the adaptiveDelegate will ask for the modal presentation style (UIModalPresentation|Style). We can return to presentation style based on size of classes. And then presentation controller asks the delegate to vend a new presentation controller to temporarily replace the view controller that is currently being presented.

3. Unwind Segues & Custom Containers:

In iOS 9, the Unwind segues have been fed with more power than the earlier versions.

In iOS 9, when an Unwind segue is triggered, it looks for the view controller with the selector for unwind segue.
The system first goes to the parent view controller of source controller (view controller which triggered the Unwind segue) & then checks if it has the child view controllers. If parent view controller has any number of child view controllers, then it iterates through its child view controller to find the destination (which has implemented the Unwind segue IBAction) view controller.
And if doesn’t have any number of child view controllers, it goes to the top level of the view hierarchy and repeats the same.

Minor Problems and their Solution:

During thorough analysis and execution of all the features that the iOS 9 Storyboard possesses, some problems emerged too which are worth a mention here:

Problems:

1- Complexity: Storyboards can quickly become burdensome & complex for large projects
2- Source Control: As Storyboard is stored as one file so, every change you or a team member makes to a Storyboard affects the same file. This is less of a problem when working with XIB files since each XIB file represents one scene of the user interface)

Solution:
In order to overcome these issues, we found a useful solution. Our Findings in this regard showed that a developer needs to split the one Storyboards into a set of smaller Storyboards. And to connect the Storyboards, the developer must write the code for loading the storyboards and invoking instantiateInitialViewController() on the storyboards.

For example:

let storyboard = UIStoryboard(name: “Main”, bundle: NSBundle.mainBundle())
let viewController = storyboard.instantiateInitialViewController()

if let viewController = viewController {
self.presentViewController(viewController, animated: true, completion: nil)
}

Leave a Reply

Your email address will not be published. Required fields are marked *