I am new to objective C so please forgive me if this is a stupid question (and I have searched!)
I am using storyboards in xcode (4.4.1) and I have 2 UIViewControllers
I am trying to programmatically switch between them (not sure if that’s the right terminology?)
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"BookingView"];
[self presentModalViewController:vc animated:YES];
The above code works perfectly later on in my project, but I when i try call if in an if() in my viewdidload method in the first UIViewController it doesn’t work. Help please!
You shouldn’t perform such task in the viewDidLoad: method.
You’re trying to present a view controller modally on top of another that’s only been allocated in memory and loaded, but it’s not visible yet. That means your presentation won’t work. You should move your code to viewDidAppear:
I recommend you to read this guide to learn the basics about view controller delegation: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40007457