Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard reference in Xcode, where should we use it?

Tags:

xcode

ios

xcode7

There is one new control in Xcode7 beta named as Storyboard Reference. Below is its image.

enter image description here

It has its description as

Provides a placeholder for a view controller in an external storyboard. Segues connected to this placeholder will instantiate the referenced view controller at runtime.

So the questions are

  1. In which situations should we use this?
  2. Is this used to connect two storyboard's view controllers via segue?
  3. Is this approach used to replace VC of another storyboard programatically?
  4. Will it work on older iOS version(before iOS 9)?
like image 421
Yogesh Suthar Avatar asked Jun 11 '15 05:06

Yogesh Suthar


People also ask

How do I use storyboard reference in Xcode?

storyboard and choose Refactor to Storyboard ... from Xcode's Editor menu. Xcode prompts you to name the storyboard which the Note View Controller scene is moved to. Name the storyboard NoteViewController. storyboard and click Save.

Should I use storyboard in Xcode?

Another benefit to using Storyboards (over creating views programmatically) is that you get to see what your view will look like at runtime without having to run your app. You can quickly make a change in Interface Builder and immediately see what it'll look like – without waiting for Xcode to compile and run.


2 Answers

UPDATE (January 6, 2016): I just want to quickly mention that using Storyboard references is very simple and is going to help you use Storyboards in a much more clean and maintainable way. A good use case for it is e.g. a UITabBarController with multiple tabs. Just create one Storyboard for each tab and in your Main.Storyboard link to those individual Storyboards using Storyboard references. Usage is very straightforward: after creating a Storyboard reference you only need to give it the filename of the individual Storyboard that you want to link to and set the initial view controller within that individual Storyboard. That's it! :)

What follows now is the original answer I gave to @YogeshSuthar's question.

  1. this can be used in cases where you are using multiple storyboards in your app. until now you'd have to instantiate view controllers from other storyboards programmatically, seems like now you can just use this reference and create your segue in the storyboards just like with view controllers from the same storyboard

  2. yes, you connect one view controller from your current storyboard with another view controller from a different storyboard and you can create a segue between these two

  3. yes, this can be used to replace the code that was formerly used to instantiate view controllers from other storyboards programmatically

  4. [UPDATE thx to @AlexBasson] Storyboard references can deployed to iOS 8, OS X 10.10 and watchOS 1.

like image 113
nburk Avatar answered Oct 05 '22 09:10

nburk


Usage of Storyboard Reference

Well other answer's are correct to my questions.

And I want to post the usage of the Storyboard Reference which is used to open View controllers from another storyboard via segue without writing any code. :)

Steps

  1. First create 1 new storyboard name it anything you want(I named it NewStoryboard).
  2. Place your View controller(or any View Controller) in NewStoryboard.
  3. Give it a Storyboard ID(I have given newVC).

enter image description here

  1. Switch back to your main storyboard.
  2. Drag and drop Storyboard Reference control in this storyboard.
  3. Select the Storyboard Reference control and select Attributes Inspector.
  4. Select your new storyboard NewStoryboard.
  5. Provide Reference ID as newVC(which you used in NewStoryboard storyboard).
  6. Connect this Storyboard Reference via segue from ViewController. Now it will open this VC via segue without writing code. :)

enter image description here

like image 28
Yogesh Suthar Avatar answered Oct 05 '22 07:10

Yogesh Suthar