Delegate between two views in ios (delegate)

Source: Internet
Author: User

Delegate between two views in ios (delegate)

Currently, two views (ViewController and ViewController1) are redirected from ViewController to ViewController1 with parameters. After selecting the data in ViewController1, valid data is taken back to ViewController and the preceding functions are delegated.

Project: Click to download

I. Main ViewController code

// Click the event button-(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 of ViewController1Delegate-(void) selectData :( NSString *) text {dispatch_async (dispatch_get_global_queue (cost, 0 ), ^ {[self. listArray removeAllObjects]; for (int I = 0; I <5; I ++) {[self. listArray addObject: [NSString stringWithFormat: @ "row % d: % @ _ % d", I + 1, text, arc4random_uniform (100)];} dispatch_async (dispatch_get_main_queue (), ^ {[self. dataTableView reloadData];}) ;});}

Ii. Main ViewController1 code

// ViewController1.h // delegate is written before # import. Otherwise, the system may Delegate Cannot find protocol declaration @ protocol ViewController1Delegate; @ protocol ViewController1Delegate
 
  
@ Optional-(void) selectData :( NSString *) text; @ end // ViewController1.m-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {if ([self. delegate respondsToSelector: @ selector (selectData :)]) {// pass the value [self. delegate selectData: [self. listArray objectAtIndex: indexPath. row]; [self. navigationController popViewControllerAnimated: YES] ;}}
 


III,


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.