------------------
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
- 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.
Page jumps and values for storyboard under Swift