Xcode: Display Login View in applicationDidBecomeActive
Posted
by
Patrick
on Stack Overflow
See other posts from Stack Overflow
or by Patrick
Published on 2012-11-22T16:07:55Z
Indexed on
2012/11/26
11:06 UTC
Read the original article
Hit count: 257
In my app I would like to show a login screen - which will be displayed when the app starts and when the app becomes active. For reference, I am using storyboards, ARC and it is a tabbed bar application.
First off, I have this method which returns the topViewController.
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [self topViewController:presentedViewController];
}
And I call this method here:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ( ... ) { // if the user needs to login
PasswordViewController *passwordView = [[PasswordViewController alloc] init];
UIViewController *myView = [self topViewController:self.window.rootViewController];
[myView presentModalViewController:passwordView animated:NO];
}
}
To an extent this does work - I can call a method in viewDidAppear
which shows an alert view to allow the user to log in. However, this is undesirable and I would like to have a login text box and other ui elements. If I do not call my login method, nothing happens and the screen stays black, even though I have put a label and other elements on the view.
Does anyone know a way to resolve this? My passcode view is embedded in a Navigation Controller, but is detached from the main storyboard.
© Stack Overflow or respective owner