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
- 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
- Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) {
- var thesegue = Segue.destinationviewcontroller as Secondviewcontroller
- Thesegue.text = "Pass"
- }
|
(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
- var THIRDVC = Self.storyboard?. Instantiateviewcontrollerwithidentifier ("Thirdviewcontroller") as Thirdviewcontroller
- Thirdvc.text = "Pass"
- 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
- var storyboard = Uistoryboard (name: "New", Bundle:nil)
- var NEWVC = storyboard.instantiateviewcontrollerwithidentifier ("Newviewcontroller") as Newviewcontroller
- Newvc.text = "Pass"
- 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!