Method of passing data between controllers (segue)

Source: Internet
Author: User

In the login screen, click Login, verify the account password, then jump to the next window. The user's data is passed from the first controller to the next one. The implementation method is as follows:

/** Click the login button */-  (ibaction) login { //account:qqq     Password: www    if (! [self.accountfield.text isequaltostring:@ "QQQ"]) {        [mbprogresshud showerror:@ "user name does not exist:"];     //mbprogresshud for third party         return; used in previous blogs                                       A great loading effect (transparent indicator layer HUD) frame in the    //class library     }                                                    //Address: https://github.com/jdg/MBProgressHUD   &Nbsp;if (![ self.pwdfield.text isequaltostring:@ "www"]) {        [ mbprogresshud showerror:@ "Password does not exist:"];         return;    }         //Add load Cloak     [mbprogresshud showmessage:@ "Loading ..."];         dispatch_after (Dispatch_time (dispatch_time_now,  (int64_t) (2 *  NSEC_PER_SEC)),                    dispatch_get_main_queue (), ^{                        //hidden Cloak after successful loading ( Loading page)                         [MBProgressHUD hideHUD];                       //Implementation Jump                         [self performseguewithidentifier:@ "Login2contact"  sender:nil];     });} After the/** * executes the segue, this method is called before the jump  * typically pass data to the next controller  */-(void) Prepareforsegue: (uistoryboardsegue *) Segue sender: (ID) SENDER{    //1, get target controller (contact list Controller)      uiviewcontroller *contactvc = segue.destinationviewcontroller;             //2, setting title     contactVc.navigationItem.title  = [nsstring stringwithformat:@ "%@ 's contact List", Self.accountField.text];}

Performseguewithidentifier:sender:

Use Performseguewithidentifier: Method can execute a segue, complete interface jump

Next study Performseguewithidentifier:sender: The complete execution of the method

/******************************************************/[self performseguewithidentifier:@ "Login2contacts" sender:nil];//This self is the source controller/******************************************************/

1, according to identifier to find the corresponding line in storyboard, new Uistoryboardsegue object
Set the Sourceviewcontroller of the Segue object (source Controller)
New and set Destinationviewcontroller (target controller) for the Segue object


2, call Sourceviewcontroller The following method, do some pre-jump preparation work and incoming created Segue object

/******************************************************/-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender :(ID) sender;//This sender is the original performseguewithidentifier:sender: in the incoming sender/**************************************** **************/

3. Call the-(void) Perform of the Segue object; method starts to perform the interface jump operation
Get the Uinavigationcontroller where Sourceviewcontroller is located
Call Uinavigationcontroller's push method to press the Destinationviewcontroller into the stack to complete the jump

Method of passing data between controllers (segue)

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.