Reputation: 393
I've a navigationcontroller. In my secondview, i want to have a button, that when is tapped, go to the first viewController and set a text there.
So, in my button (secondView) I have:
SearchViewController *svc=[[SearchViewController alloc]init];
[svc setValueMethod:@"randomString"];
[self.navigationController popToRootViewControllerAnimated:YES];
In my firtView:
-(void)setValueMethod:(NSString *)myPassedString
{
_searchField.text = myPassedString;
}
But the _searchField now is null. But when you first enter on the app it works, ok and you can make _searchField.text = @"aString"; that work. But after popping from the secondView it get's null!
Can someone help me with that?
Upvotes: 0
Views: 224
Reputation: 14834
The reason is that you created a new instance of SearchViewController called svc by this line: SearchViewController *svc=[[SearchViewController alloc]init];. But this svc instance is not the same as the original instance of SearchViewController (the one that you first saw when you enter the app).
You need to use delegate protocol. It is used for this type scenario. This SO has a code example.
Upvotes: 2