Before jumping the page we may decide whether to enter the correct data, as shown, if there is no data input pop-up prompt, do not jump.
One: page Jump
1. On the first page, put a label on a TextField and a button
2. Put two labels and a button on the second form, and specify a Viewcontroller
3. Create a Segue connection two forms, open mode Select Modal, and give Segue "OpenView"
3. On page 1, create a reference to the input text box and click Action on the button
Determine if the text has data in action, and if not, open a new form if there is one
@IBAction func Passnametoview (sender:anyobject) {guard Let text= Tename.textwhere!text.isemptyElse{let title="Warning"Let message="Please enter name!"Let oktext="Ok"Let alert=Uialertcontroller (Title:title, Message:message, PreferredStyle:UIAlertControllerStyle.Alert) let Okbut Ton=uialertaction (Title:oktext, style:. Cancel, Handler:nil) alert.addaction (okbutton) Presentviewcontroller (Alert, animated:true, Completion:nil)return; } self.performseguewithidentifier ("OpenView", Sender:self)//or if let text = Tename.text where!text.isempty}
This allows you to open a new form.
4. Returning the original form from the new form
The button in page 2 creates an action code as follows
@IBAction func backtoparent (sender:anyobject) { self.dismissviewcontrolleranimated (True , Completion:nil) }
Two. Page Pass value
1. In page 2, declare a string variable to receive the transmitted information and a lable reference, displayed in the label after the form is loaded
@IBOutlet weak var receivename:uilabel! "" Override func viewdidload () { super.viewdidload () // Do any additional setup after loading The view. = receivedstr }
2. Page 1 override the Prepareforsegue method to pass value input values to page 2
override func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) { if'openView' { if'? Secondviewcontroller { = tename.text! } }}
OK the whole process is complete.
Full code: Judging condition page jumps. zip
"Swift Learning Notes" page jump condition judgment and pass value