Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have solved it by putting a login view without any segues (to or from it) like in the screenshot below:</p> <p><img src="https://i.stack.imgur.com/hNIcN.png" alt="enter image description here"></p> <p>Then, I used a custom class in the tab bar controller to show it whenever I need it. </p> <p>In the tab bar controller class, I use 'viewDidLoad' to fire up the login view. To show the modal view, I do have a singleton thingy that stores some state, say BOOL isAuthenticated, where I do the magic:</p> <pre><code>- (void) performLoginIfRequired: (UIViewController *) source { if (!self.isAuthenticated) { NSLog(@"Is not authed"); UIStoryboard *storyboard = [UIApplication sharedApplication].delegate.window.rootViewController.storyboard; UIViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"loginScreen"]; [source presentModalViewController:loginController animated:YES]; } else { NSLog(@"Is authe"); } } </code></pre> <p>And, in my case, I wanted it to be shown when the app first starts, but also when it enters foreground again. So, I registered my tab bar controller with the notification center, so I get notified if the app is coming back:</p> <pre><code>-(void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; } </code></pre> <p>In the willEnterForeground method, I do:</p> <pre><code>-(void) willEnterForeground: (NSNotification *)notification { [[myStateThingy defaultState] performLoginIfRequired:self]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload