将NSString从子级传递给ModalViewController的父级 [英] Pass a NSString from Child to Parent for ModalViewController
问题描述
我的父级ViewController类包含一个UISearchBar.我有一个UIButton,它将通过下面的代码推送到新的ViewController
My parent ViewController class contains a UISearchBar. I have a UIButton that will push on a new ViewController via the code below
AddViewController *addViewController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];
[self presentModalViewController:addViewController animated:YES];
[addViewController release];
在AddViewController中,向用户显示动物名称的TableView.在
In the AddViewController the User is presented with a TableView of animal names. On the
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
我提取动物名称并将其存储在NSString中.然后我用
I extract the the animal name and store it in an NSString. I then dismiss the AddViewController by
[self dismissModalViewControllerAnimated:YES];
我的问题是如何将NSString动物名传递给AddViewController的父级ViewController?我正在尝试将动物名称放置在UISearchBar中
My Question is How do I pass the NSString animal name to the Parent ViewController of AddViewController? I'm attempting to place the animal name in the UISearchBar
推荐答案
您需要创建一个委托.
http://iosdevelopertips.com/objective -c/the-basics-of-protocols-and-delegates.html
这些允许您与父视图控制器进行通信,并在您的情况下传递变量.
These allow you to communicate with the parent view controller, and in your case, pass a variable.
这篇关于将NSString从子级传递给ModalViewController的父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!