0

親の ViewController クラスには UISearchBar が含まれています。以下のコードを介して新しいViewControllerをプッシュするUIButtonがあります

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

これらを使用すると、親View Controllerと通信でき、場合は変数を渡すことができます。

于 2010-11-08T15:33:43.660 に答える
0

親View Controllerでプロパティを作成できます。これを呼び出して子から更新できます

self.parentViewController.searchBarText = animalNameString;

子が閉じられたら、親の viewWillAppear メソッドで UISearchBar テキストを設定します

于 2010-11-08T16:03:27.750 に答える