I’m developing a new iOS app
I have a view controller in my storyboard that has a text field. Using UITextFieldDelegate, upon pressing search on the keyboard I perform the segue to a table view controller.
But this second table view controller is embedded in a navigation view controller. The first view controller is not a part of it.
Segue is done using:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SearchTableViewController"];
[vc setModalPresentationStyle:UIModalPresentationFlipHorizontal];
[self presentModalViewController:vc animated:YES];
What I want to do is, pass data from the first view controller’s text field to the other view controller in a NSString. How do I do this?
There’s an IBOutlet, searchField on the text field in the first.
And in the second’s header file a property
@property (nonatomic, strong) NSString *searchText.
So how do I go about passing searchField.text to searchText?
When you instantiate your view controller you should cast it as your custom view controller subclass. If you do this you can then set the
searchTextproperty value.