Share a about storyboard jump and pass value _ios

Source: Internet
Author: User

Written in front of the knowledge:

Because Apple pushes Storyboard and at present, the Apple Watch also uses Storyboard to know, tomorrow application estimate all is Storyboard's world.
(The level is limited, the wrong place is unavoidable, hope Haihan)

Many people still seem to be using XIB, to Storyboard how to jump seems to be ignorant ...

Well, given the morning group, someone asked how to jump, how to pass the value and so on. To do a summary, at the same time to provide you with a number of methods and references.
***

1. The simplest way

Drag and drop, this is not much to explain it. Drag directly to another view controller, select Show, on the line.

2. Using the Segue method (this is mainly the value of Method 1)

Connect a good line, click on the middle section, set Identifier.

Then call the Performseguewithidentifier method.

(Note: In the Demo, it is directly to connect Tableviewcontroller and Secondviewcontroller, instead of clicking on the Cell indicator to connect)

You can perform a jump operation by performing the following methods.

Performseguewithidentifier ("Secondsegue", sender:self)

How do I pass values?

Very simply, you need to invoke the Prepareforsegue method (because this is the parent view-> the child view, so use Destinationviewcontroller)

 Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) {
var thesegue = Segue.destinationviewcontroller as secondviewcontroller
thesegue.text = "Pass"
}

(Note: Here, Swift's auto complement may not be valid, so if there is no destinationviewcontroller, it's okay to play backwards.)

The text here is the variable I declare in the child view, which is used to set the value of the Label.

Ps:

In general, we all use the way of wiring, here we tell you another way, is to use Viewwithtag. I was previously set to 100 in the Label control Tag.

Of course you can also use the line, and using Viewwithtag can be handy when we customize the cell, without having to create a separate cell class.

3. Using Self.storyboard

Using the Self.storyboard method, you do not need to connect, you can jump between views. However, you must set the Storyboard ID.

And then use the following methods to jump and transfer values

 var THIRDVC =  
 Self.storyboard? Instantiateviewcontrollerwithidentifier ("Thirdviewcontroller") as 
 thirdviewcontroller
thirdVC.text = " Pass "

Because it is in the same Storyboard inside the jump, so self.storyboard can meet the demand.

Don't understand? Look at the last method:

4. Using Uistoryboard

XIB method, we need to use nibname, also if we want to separate multiple sence in different storyboard inside, what to do?

This time, you can not use the Self.storyboard.

But:

var storyboard = Uistoryboard (name: "New", Bundle:nil)
var newvc = Storyboard.instantiateviewcontrollerwithidentifier ("Newviewcontroller") as Newviewcontroller
newVC.text = " Pass "
Self.navigationcontroller? Pushviewcontroller (NEWVC, Animated:true)

is not and xib have the same feeling, so that you can storyboard divided into several, each inside put a few sence.

The advantage of this is that when you need to do a number of different functions of the application of the module, separate into the different Storyboard, not affect each other.

Relative to Xib, each folder requires only 1 storyboard files, and Swfit files are available.

The above description is a small series to share storyboard jump transfer value of the relevant knowledge, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.