iOS two view delegate (delegate) pass value

Source: Internet
Author: User

Existing two Views (Viewcontroller,viewcontroller1), jump to ViewController1 from Viewcontroller with parameters in ViewController1 With valid data back to Viewcontroller after the data is selected, the delegate implements the above functions.

Project: Click to download

First,viewcontroller main code

button click Event-(ibaction) CLICKSEARCHBTN: (ID) sender {[[[        uiapplication sharedapplication] Keywindow] endediting:yes];        ViewController1 *_viewcontroller = [[[[ViewController1 alloc] init] autorelease];    _viewcontroller.delegate = self;    _viewcontroller.transtext = Self.textField.text;        [Self.navigationcontroller Pushviewcontroller:_viewcontroller animated:yes];} Proxy method for Viewcontroller1delegate-(void) Selectdata: (nsstring*) text{    Dispatch_async (Dispatch_get_global_queue ( Dispatch_queue_priority_default, 0), ^{        [Self.listarray removeallobjects];        for (int i=0; i<5; i++) {            [Self.listarray addobject:[nsstring stringwithformat:@ '%d rows of data:%@_%d ', I+1,text, Arc4random_uniform (+)];        }        Dispatch_async (Dispatch_get_main_queue (), ^{            [Self.datatableview reloaddata];        });    }

TwoViewController1 Main code

viewcontroller1.h//delegate written before #import, otherwise it might delegate cannot find protocol Declaration@protocol Viewcontroller1delegate, @protocol viewcontroller1delegate <NSObject> @optional-(void) Selectdata: (nsstring*) Text, @end//viewcontroller1.m-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{        if ([Self.delegate respondstoselector: @selector (selectdata:)]) {                //pass value via a delegate agreement        [self.delegate Selectdata:[self.listarray ObjectAtIndex:indexPath.row]];        [Self.navigationcontroller Popviewcontrolleranimated:yes];}    }


Three


iOS two view delegate (delegate) pass value

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.