Page jumps and values for storyboard under Swift

Source: Internet
Author: User

------------------

1. The simplest method


Drag and drop, this will not be explained more. Drag directly to another view controller, select Show, and it's OK.

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

Connect the line, click the middle part of the connection, set the Identifier.

Then call the Performseguewithidentifier method.

(Note: In the Demo, the Tableviewcontroller and Secondviewcontroller are connected directly, instead of clicking on the Cell's indicator to connect)

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

Copy Code
  1. Performseguewithidentifier ("Secondsegue", sender:self)



How do I pass a value?

Very simple, you need to call the Prepareforsegue method (because this is the parent view-and child view values, so use Destinationviewcontroller)

Copy Code
  1. Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) {
  2. var thesegue = Segue.destinationviewcontroller as Secondviewcontroller
  3. Thesegue.text = "Pass"
  4. }



(Note: Here, Swift's auto-completion may fail, so if there is no destinationviewcontroller, it's okay to play backwards.)

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

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

Of course you can also use the line, Viewwithtag can be used when we customize the cell, without the need to create a separate cell class.

3. Using Self.storyboard

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

Then use the following methods to jump and pass the value

Copy Code
  1. var THIRDVC = Self.storyboard?. Instantiateviewcontrollerwithidentifier ("Thirdviewcontroller") as Thirdviewcontroller
  2. Thirdvc.text = "Pass"
  3. Self.navigationcontroller?. Pushviewcontroller (THIRDVC, Animated:true)



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, how to do?

At this time, you can't use Self.storyboard.

But:

Copy Code
  1. var storyboard = Uistoryboard (name: "New", Bundle:nil)
  2. var NEWVC = storyboard.instantiateviewcontrollerwithidentifier ("Newviewcontroller") as Newviewcontroller
  3. Newvc.text = "Pass"
  4. Self.navigationcontroller?. Pushviewcontroller (NEWVC, Animated:true)



And XIB is similar to the feeling, so you can divide Storyboard several, each inside put a few sence.

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

As opposed to XIB, only 1 Storyboard files per folder are required, and Swfit files are available.

Page jumps and values for storyboard under Swift

Related Article

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.