Search code examples
iphoneiosobjective-cviewuivewcontroller

error when i am calling next view controller


i am getting an error when i am calling next view controller, i want to call a view controller that a action continue .this screen will come appear first time only when we run first time. controller is not going next view.

-(void)viewDidLoad
{
    welcomePage *temp = [[welcomePage alloc]initWithNibName:@"welcomePage" bundle:nil];       
    [self presentViewController:temp animated:YES completion:^(void){}];

}

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


Solution

  • Try this one..

    You change the code in Appdelegate.m didFinishLaunchingWithOptions method like this

    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = nav;
    

    And in your ViewDidLoad method like this..

    welcomePage *temp = [[welcomePage alloc]initWithNibName:@"welcomePage" bundle:nil];       
    [self.navigationController presentViewController:temp animated:YES completion:nil];
    

    For dismissing viewcontroller you can write following code in welcomepage button action

    -(IBAction)dismiss:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
    }