Reputation: 29326
I have everything implemented, and the following method that fires when I return to the source view controller:
- (IBAction)returned:(UIStoryboardSegue *)segue {
...
}
I want to take the value from the UITextField in the view I'm returning from, and set a value in my source view (or the view that calls this method) to the value of that UITextField.
I tried this:
- (IBAction)returned:(UIStoryboardSegue *)segue {
AddTextViewController *returnedFromViewController = segue.destinationViewController;
NSString *inputtedText = returnedFromViewController.textField.text;
self.foo = inputtedText;
}
But I get this error:
[RootViewController textField]: unrecognized selector sent to instance 0x8dc0250
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController textField]: unrecognized selector sent to instance 0x8dc0250'
What am I doing wrong in that code above? There's hardly any documentation on this, so it's very hard to search around myself.
Upvotes: 2
Views: 991
Reputation: 9414
The best way to do this is to implement a protocol / delegate. The delegate will handle any requests from your destination view controller and send the data back to your source view controller.
http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html
Upvotes: 0
Reputation: 49034
You're using the wrong controller. You want the segue's sourceViewController
, not the destinationViewController
. Otherwise, you're doing it all correctly.
Upvotes: 3