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!
use this code
-(void)viewDidLoad
{
welcomePage *temp = [[welcomePage alloc]initWithNibName:@"welcomePage" bundle:nil];
[self presentViewController:temp animated:YES completion:nil];
}
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 .
该错误意味着您正在尝试从当前不在屏幕中的视图控制器中呈现模式视图控制器。
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!
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];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.