5

I'm facing a problem trying to link my UIViewController but I got my final error.

Attempt to present ViewController whose view is not in the window hierarchy

Here's my code :

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Wokay"])
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"Vibes"];
        [self.window.rootViewController presentViewController:vc animated:YES completion:nil];

    }
}

Code Error:

Warning: Attempt to present <ViewController: 0x110634bc0> on <Login: 0x10951e7f0> whose view is not in the window hierarchy!
batman
  • 1,937
  • 2
  • 22
  • 41
user3546239
  • 159
  • 1
  • 10

1 Answers1

2

It seems like that your UIViewController(Login) is not in Window Hierarchy.

You may be adding your LoginViewController as a subView in UIWindow. If so, set it as the UIWindow's rootViewController

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //Other code parts

    [self.window setRootViewController:loginViewController];
    return YES;
}

OR

If you are adding LoginViewController's view as subView in any UIViewController(say FirstViewController), present it instead

In your FirstViewController.m,

-(void)viewDidLoad{
    [super viewDidLoad];


    LoginViewController *loginViewController ;//Instantiate LoginViewController here
    [self presentViewController:loginViewController animated:NO completion:Nil];
}
Bilal Saifudeen
  • 1,677
  • 14
  • 14
  • No luck . I'm using both also UIViewController . when I set other UIViewController the redirect works but when i put another UIViewController(LOGIN) , it will make it to stuck. – user3546239 May 20 '14 at 04:58
  • @user3546239 so the question is: what's the diffferent between other UIViewController and LOGIN? did you assign the correct storyboard ID to LOGIN? – highwing May 20 '14 at 05:01