1

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!

Jamal Zafar
  • 2,179
  • 2
  • 27
  • 32
square
  • 162
  • 2
  • 13

5 Answers5

0

use this code

-(void)viewDidLoad
{
    welcomePage *temp = [[welcomePage alloc]initWithNibName:@"welcomePage" bundle:nil];       
    [self presentViewController:temp animated:YES completion:nil];
}
D-eptdeveloper
  • 2,430
  • 1
  • 16
  • 30
0

If You are using Storyboard : Use this

instantiateViewControllerWithIdentifier

    UIViewController objController  = [self.storyboard instantiateViewControllerWithIdentifier:@"StoryBoard Id"];
 [self presentViewController:objController animated:YES completion:nil];

To Set Storybaord ID , Check Here .

Community
  • 1
  • 1
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
0

That error means you are trying to present a modal view controller from a view controller that is not currently in the screen.

Odrakir
  • 4,254
  • 1
  • 20
  • 52
0

This error means that you are trying to present 'welcome page' from a view that is not on the screen yet.

Knowing that simply moving the code to the viewDidAppear method doesn't work for you, what you can try to do is this:

-(void)viewDidAppear
{
    [self presentWelcome];
}

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

What happens here is that when the view appears (so when it is in the view hierarchy), the controller starts a function that calls the other viewController. hope this solves your problem.

Hope this helps you!

Joris416
  • 4,751
  • 5
  • 32
  • 59
  • i used this code .it is not working .i am calling one viewcontroller to welcomepage controller but its not going in that screen.both are xib not a storyboard – square Sep 10 '13 at 08:25
  • just to rule this out: try to replace ^(void){} with NULL. and another possibility is that you are using storyboards: if you do, you should change the way you create an instance of your viewcontroller. please tell me if you do and what's the result of my suggested edit. – Joris416 Sep 10 '13 at 08:32
  • Warning: Attempt to present on whose view is not in the window hierarchy! welcome page is not coming ,i am using this code inside viewDidLoad method – square Sep 10 '13 at 09:30
  • I updated my answer because the error you give me confirms that you are loading you viewController to early. please tell me whether it works. – Joris416 Sep 10 '13 at 09:58
0

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];
}
kalyani puvvada
  • 496
  • 4
  • 12
  • kalyani puvvada ,it is working ,now how to go viewcontroler after clicked the button that is in welcome page. – square Sep 10 '13 at 12:41