I’m coding an iphone app which takes user inputs from First View (RootViewController) and then it needs to pass on the inputs to the “results” View Controller which is another view which uses the inputs to query a server, parse JSON string and displays results in the UITableView. I’m stuck at how to “send” these string (from user inputs on RootViewController) to the 2nd ViewController…Any idea?
Thx in advance
Stephane
There are three ways to do this, depending on how the views are set up.
First, you can use
NSNotificationCenterto post a notification of the string. The other view would register as an observer for the notification and can gather the information when it is posted.Secondly, if the second view controller is presented by the first, i.e. you alloc/init the VC and present it with a navigation controller, you can create a property in the second VC and set it from your root. In the header of the second VC, you would create the following:
and
then
@synthesize someString;in the implementation file. Doing this lets you set the value before the view is presented.Lastly, if the views are not related, as in the second VC is not presented by the root, you would create an IBOutlet from the root to the second VC. Assuming you have the attribute set up like in the last solution, you would call something along the lines of
self.secondVC.someString = myStringToPass;Hopefully one of those helps
Edit: Realized I had commented out the link to NSNotificationCenter….oops