0

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

AddViewController *addViewController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];
[self presentModalViewController:addViewController animated:YES];
[addViewController release];

在 AddViewController 中,用户会看到动物名称的 TableView。在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

我提取动物名称并将其存储在 NSString 中。然后我通过关闭 AddViewController

[self dismissModalViewControllerAnimated:YES];

我的问题是如何将 NSString 动物名称传递给 AddViewController 的父 ViewController?我正在尝试将动物名称放在 UISearchBar

4

2 回答 2

1

您需要创建一个代表。

http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html

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

于 2010-11-08T15:33:43.660 回答
0

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

self.parentViewController.searchBarText = animalNameString;

当孩子被解雇时,在父母的 viewWillAppear 方法中设置 UISearchBar 文本

于 2010-11-08T16:03:27.750 回答