Apologies if my terminology is a bit off, new to objective C!
I am trying to pass a value from one UIViewController class to another. I am using storyboards. I am able to display the second ViewController using the following code:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
[self presentModalViewController:vc animated:YES];
That works fine. In my second ViewController’s (FormView) header file I set a property like so:
@interface FormController : UIViewController {
NSString *selectedBooking;
}
@property (nonatomic, retain) NSString *selectedBooking;
@end
How do I “pass the value” from my first Controller to the second Controller? As far as I understand I have to set the property like so:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"FormView"];
vc.selectedBooking = @"test";
[self presentModalViewController:vc animated:YES];
Which gives me the error: Property ‘selectedBooking’ not found on object of type ‘UIViewController’.
What is the correct way to set the property? Is there something else I should be using rather that instantiateViewControllerWithIdentifier?
Thanks
You’ll need to cast it.
i.e.
then the rest of your code will work 😀