1
votes

I am building my app which is asking the user to authenticate. In case the session with the server is expired it pops the login controller. So far so good. The problem is that when the user is opening the app and the first screen (empty table view) is showed then the login screen. I know it's a detail but I think it's not right.

This is my MainViewController which is under Navigation Controller. Code:

-(void)viewDidAppear:(BOOL)animated{
NSLog(@"Username: %@",[MMCurrentUser email]);

//Check if the user is logged and shows the sites else it shows the login screen

if(![MMCurrentUser email]){

    LoginLaunch *ll;
    ll= [[LoginLaunch alloc]initLoginScreenFrom:self];

}}

If I put that code in willAppear I get the warning: "Presenting view controllers on detached view controllers is discouraged." and the problem still exist.

Anyone knows a good way to solve this problem?

1
what about -presentViewController:animated:completion: with animated == NO (immediately) first thing inside -viewDidAppear ? Does your underlying view controller show for some frames, or is it successfully hidden? - Nicolas Miari
Perhaps a cleaner approach would be to default your first view controller to some sort of 'Wait a second... (checking login)' screen, and from there transition to different view controllers depending on the result. - Nicolas Miari
It's much faster but the empty view is showing. About the "Wait for a second" I think it's a good idea because my LoginLaunch class it goes back to the view controller that called it as soon as the user is logged in. I am thinking to replace the "Wait for a second" with a view identical to Splash screen so the user won't notice the difference. Can you please reply this an answer? - BlackM

1 Answers

1
votes

Perhaps clean approach would be to make your first view controller to look like some sort of 'Wait a second... (checking login)' screen -or better, as you mentioned in the comments- a smooth continuation of your launch image; and from there, transition to different view controllers depending on the result of the authentication:

  • Success: proceed to navigation controller/table view controller.
  • Failure: Proceed to 'login' view controller.