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,