More on Storyboards

In this exercise, you created a storyboard, set up a few view controllers, laid out their interfaces, and created some segues between them. This is the basic idea behind storyboards, and while there are a few more flavors of segues and types of view controllers you can set up, you get the idea. A storyboard replaces lines of code.

For example, a push segues replace this code:

-​ ​(​v​o​i​d​)​t​a​b​l​e​V​i​e​w​:​(​U​I​T​a​b​l​e​V​i​e​w​ ​*​)​t​a​b​l​e​V​i​e​w​
 ​ ​ ​ ​d​i​d​S​e​l​e​c​t​R​o​w​A​t​I​n​d​e​x​P​a​t​h​:​(​N​S​I​n​d​e​x​P​a​t​h​ ​*​)​i​p​
{​
 ​ ​ ​ ​U​I​V​i​e​w​C​o​n​t​r​o​l​l​e​r​ ​*​v​c​ ​=​ ​[​[​U​I​V​i​e​w​C​o​n​t​r​o​l​l​e​r​ ​a​l​l​o​c​]​ ​i​n​i​t​]​;​
 ​ ​ ​ ​[​s​e​l​f​.​n​a​v​i​g​a​t​i​o​n​C​o​n​t​r​o​l​l​e​r​ ​p​u​s​h​V​i​e​w​C​o​n​t​r​o​l​l​e​r​:​v​c​]​;​
}​

While this seems nice, storyboarding, in our opinion, is not very useful. Let’s go through the pros and cons. First, the pros:

  • Storyboards can be used to easily show off the flow of an application to a client or a colleague.

  • Storyboards remove some simple code from your source files.

  • Tables with static content are easy to create.

  • Prototype cells replace the need to create separate XIBs for custom table view cells.

  • Storyboards sure do look pretty.

The cons, unfortunately, outweigh the pros:

  • Storyboards are difficult to work with in a team. Typically, a team of iOS programmers breaks up the work by having each member focus on a particular view controller. With a storyboard, everyone has to do their work in the same storyboard file. This can quickly lead to clutter and difficulties with version control.

  • Storyboards disrupt the flow of programming. Let’s say you are writing a view controller and adding the code for a button that presents a view controller modally. You can do that pretty easily in code – alloc and init the view controller, and send presentViewController:animated:completion: to self. With storyboards, you have to load up the storyboard file, drag some stuff onto the canvas, set the Class in the identity inspector, connect the segue, and then configure the segue.

  • Storyboards sacrifice flexibility and control for ease of use. The work required to add advanced functionality to the basic functionality of a storyboard is often more than the work required to put together the advanced and basic functionality in code.

  • Storyboards always create new view controller instances. Each time you perform a segue, a new instance of the destination view controller is created. Sometimes, though, you would like to keep a view controller around instead of destroying it each time it disappears off the screen. Storyboarding does not allow you to do this.

Overall, storyboards make easy code easier and difficult code more difficult. We do not use them in this book, and we do not typically use them when writing our own applications. However, Apple seems to be pushing them harder in each release of Xcode, so you might one day decide that a particular application would benefit from storyboarding.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset