0

Using storyboards i have a tab bar controller with 2 views. In one view i want to have the ability to send the user in another view if is not logged in.

Show in the FirstView i have this:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if(![self loggedin])
    {
        ErrorView *wizard =  (ErrorView*)[[UIStoryboard storyboardWithName:@"Main_iphone" bundle:nil] instantiateViewControllerWithIdentifier:@"wizard"];
        [wizard setModalPresentationStyle:UIModalPresentationFullScreen];
        [self presentViewController:wizard animated:NO completion:nil];
    }
    .....

If the user is not logged in i'am getting this error:

Warning: Attempt to present on whose view is not in the window hierarchy!

Any help will be very appreciable.

Gavin
  • 8,204
  • 3
  • 32
  • 42
  • 1
    Although, Gavin's answer will do the job, check a full solution for login/logout actions http://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou – Dimitris Bouzikas Feb 19 '14 at 19:13

1 Answers1

1

In viewWillAppear, the current view controller is not yet visible, hence why it says it will appear, not did appear. You can fix it by moving your code to the viewDidAppear method.

Gavin
  • 8,204
  • 3
  • 32
  • 42