Iphone 为ModalViewController将NSString从子级传递到父级
我的父ViewController类包含一个UISearchBar。我有一个UIButton,它将通过下面的代码推送一个新的ViewControllerIphone 为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]; [
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文本我不会说“需要”-但这是一种方法。:-)没有其他方法可以干净利落地做到这一点。如果需要传递多个变量,使用委托将是最好的方法。