Edit: When solving this problem, I found that it is much easier to start with your UITabBarController
, then perform login validation via your AppDelegate.m
's didFinishLaunchingWithOptions:
method.
Question: This code is in the the application didFinishLaunchingWithOptions:
method in my AppDelegate.m
if([result isEqualToString: @"log"]) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"]; [(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO]; NSLog(@"It's hitting log"); }
It simply takes an HTTP response for the user being logged in, and takes them to my TabBarController. The problem is that it's using a push rather than a modal transition to display the page. Since presentModalViewController method is deprecated or deleted in iOS7, how can I programmatically force a modal presentation?
EDIT: )
NSString * storyboardName = @"MainStoryboard"; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil]; UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER_OF_YOUR_VIEWCONTROLLER"]; [self presentViewController:vc animated:YES completion:nil];
Open Main. storyboard and select the view controller of the scene that is already present. Open the Identity Inspector on the right and set Class to MasterViewController in the Custom Class section. With the view controller selected, choose Embed In > Navigation Controller from the Editor menu.
The old presentViewController:animated:
method has been deprecated, we need to use presentViewController:animated:completion
instead. You now simply have to add a completion
parameter to the method - this should work:
if([result isEqualToString: @"log"]) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"]; [(UINavigationController*)self.window.rootViewController presentViewController:ivc animated:NO completion:nil]; NSLog(@"It's hitting log"); }
The docs are a good place to start - the docs for UIViewController presentViewController:animated
tell you exactly what you need to know:
presentModalViewController:animated:
Presents a modal view managed by the given view controller to the user. (Deprecated in iOS 6.0. Use
presentViewController:animated:completion:
instead.)- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With