Well, I admit that I like this way of organizing multiple StoryBoard, learning!

Source: Internet
Author: User





The following reprint content is very good, follow-up supplement from the official documents to the context, really good usage.




Storyboard jump and transmit value     written in front:

because Apple pushes Storyboard and at present, Apple Watch is also used Storyboard to know that tomorrow application is estimated to be the Storyboard of the world.

(the level is limited, the difference is unavoidable, look at Haihan)

Many people seem to be using XIB, Storyboard How to jump seems mengmengdongdong ...

Well, given the morning crowd, someone asked how to jump, how to pass the value and so on. Make a summary, at the same time provide you with some methods and reference.

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

1. The simplest method


Drag, this will not be explained. Drag directly to another view controller, select Show, and it's all right.

2. Use the Segue method (here is the value of Method 1)

Connect the line, click the middle section of the connection, and set the Identifier.
The
then calls the Performseguewithidentifier method.

(note: Inside the Demo, the Tableviewcontroller and Secondviewcontroller are wired directly instead of clicking on the indicator of the Cell)

performs the following methods The jump operation is possible.

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.

[This post was edited by Dongeyoung on 2014-11-23 04:55]




Well, I admit I like this way of organizing multiple StoryBoard, learning!

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.