"Swift Learning Notes" page jump condition judgment and pass value

Source: Internet
Author: User

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

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.