[英]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! 警告:尝试显示不在窗口层次结构中的视图!
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 如果您使用的是Storyboard:请使用此
instantiateViewControllerWithIdentifier
InstantiateViewControllerWithIdentifier
UIViewController objController = [self.storyboard instantiateViewControllerWithIdentifier:@"StoryBoard Id"];
[self presentViewController:objController animated:YES completion:nil];
To Set Storybaord ID , Check Here . 要设置Storybaord ID, 请在此处检查 。
该错误意味着您正在尝试从当前不在屏幕中的视图控制器中呈现模式视图控制器。
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: 知道仅将代码移到viewDidAppear方法对您不起作用,您可以尝试执行以下操作:
-(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. 这里发生的是,当视图出现时(因此,当它处于视图层次结构中时),控制器启动了一个函数,该函数调用另一个viewController。 hope this solves your problem.
希望这能解决您的问题。
Hope this helps you! 希望这对您有所帮助!
Try this one.. 试试这个
You change the code in Appdelegate.m didFinishLaunchingWithOptions method like this 您可以像这样更改Appdelegate.m didFinishLaunchingWithOptions方法中的代码
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.. 在这样的ViewDidLoad方法中。
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 要关闭视图控制器,您可以在welcomepage按钮操作中编写以下代码
-(IBAction)dismiss:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.