View Controller Transitions

One of the first things developers learn when beginning iOS development is how to transition between the various scenes of the application and how to pass data between view controllers.1

The typical approach to this is to drag a few UIViewControllers on your storyboard (if you are using storyboards), connect them with segues, give the segues identifier names and when an event that asks for a transition occurs, make the appropriate preparations inside the prepareForSegue: method.

This approach is fine and works great for small-sized apps but when an app uses more than 2-4 scenes, then a much cleaner solution is needed to help with the maintenance and extension of the code base. 2

  1. This problem is of course hardly unique to iOS. Any application with a GUI faces this situation. The methodology used in this article can be applied to most technologies/languages.

  2. We will be using a simple 3 screen example here, but the methodology described in this article can be applied to both simple and complex (many scenes deep) hierarchies. For more complex cases, take a look at this example that goes one step further and uses the State Design Pattern to avoid cluttering the Mediator class.

Passing Data Between View Controllers

iOS View Controller Transitions served as an introduction to an efficient and extensible solution for transitioning between view controllers. In this article, we will use the same Mediator Pattern structure as a base for tackling the issue of injecting and passing data between view controllers.1


  1. Again, this problem is not unique to iOS. Feel free to apply the concepts described here in any situation you see fit.

View Controller Transitions For Big iOS Projects

The View Controller Transitions article provided a way of handling transitions between view controllers that leads to lower coupling and allows for more flexibility when it comes to extending functionality.

One might notice that with the solution described in that article, there is a possibility that we end up with a huge Mediator class, full of else-if clauses.