Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为ModalViewController将NSString从子级传递到父级_Iphone_Objective C_Uiviewcontroller_Modalviewcontroller - Fatal编程技术网

Iphone 为ModalViewController将NSString从子级传递到父级

Iphone 为ModalViewController将NSString从子级传递到父级,iphone,objective-c,uiviewcontroller,modalviewcontroller,Iphone,Objective C,Uiviewcontroller,Modalviewcontroller,我的父ViewController类包含一个UISearchBar。我有一个UIButton,它将通过下面的代码推送一个新的ViewController AddViewController *addViewController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil]; [self presentModalViewController:addViewController animated:YES]; [

我的父ViewController类包含一个UISearchBar。我有一个UIButton,它将通过下面的代码推送一个新的ViewController

AddViewController *addViewController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];
[self presentModalViewController:addViewController animated:YES];
[addViewController release];
在AddViewController中,用户将看到动物名称的表格视图。在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
我提取动物名称并将其存储在NSString中。然后,我通过

[self dismissModalViewControllerAnimated:YES];

我的问题是如何将NSString动物名称传递给AddViewController的父ViewController?我正在尝试将动物名称放置在UISearchBar中,您需要创建一个代理


这些允许您与父视图控制器通信,在您的情况下,还可以传递一个变量。

您可以在父视图控制器中创建一个属性,然后通过调用

self.parentViewController.searchBarText = animalNameString;

当孩子被解职时,在家长的ViewWillExample方法中设置UISearchBar文本

我不会说“需要”-但这是一种方法。:-)没有其他方法可以干净利落地做到这一点。如果需要传递多个变量,使用委托将是最好的方法。