Ios 不鼓励在分离的视图控制器上显示视图控制器
我将xcode 5.1.1与情节提要一起使用。我有一个主菜单上的按钮,它弹出到另一个视图控制器与此代码Ios 不鼓励在分离的视图控制器上显示视图控制器,ios,xcode,amslidemenu,Ios,Xcode,Amslidemenu,我将xcode 5.1.1与情节提要一起使用。我有一个主菜单上的按钮,它弹出到另一个视图控制器与此代码 VC *secondVC = [[VC alloc] init]; [self presentViewController:secondVC animated:YES completion: nil]; [self dismissViewControllerAnimated:YES completion: nil]; 我有一个返回按钮,上面有这个代码 VC *secondVC = [[VC
VC *secondVC = [[VC alloc] init];
[self presentViewController:secondVC animated:YES completion: nil];
[self dismissViewControllerAnimated:YES completion: nil];
我有一个返回按钮,上面有这个代码
VC *secondVC = [[VC alloc] init];
[self presentViewController:secondVC animated:YES completion: nil];
[self dismissViewControllerAnimated:YES completion: nil];
当我跳到Second时,VC xcode给了我一个错误:
不建议在分离的视图控制器上显示视图控制器
我的旋转也有问题,它不能正常工作。尝试从rootVC推送:
[self.view.window.rootViewController.navigationController pushViewController:YOUR_VIEW_CONTROLER animated:YES];
如果您试图在视图中按下、显示或弹出视图控制器,则会出现此警告。我不知道您的代码中有什么,所以很难确定您的问题,但如果您试图在ViewWillDisplay中显示新视图,请尝试使用此选项
[self performSelector:@selector(yourMethod)
withObject:nil afterDelay:0.0];
从
viewDidDisplay显示控制器:
取而代之。我在尝试从viewWillDisplay显示UIAlertController时遇到了类似的情况。由于Swift中不存在performSelector,因此我将呼叫包装为:
dispatch_async(dispatch_get_main_queue()), {
presentYourVCHere;
});
如果有人想知道如何使用swift(甚至可以在Objective C中使用),下面的代码可以帮助我克服上述问题。在viewDidLoad()中使用此代码
尝试在ViewDidDisplay中调用相同的操作。 此警告是由于在viewDidLoad或ViewWillAspect方法中显示任何视图时引起的 因此,请在 覆盖函数视图显示(动画:Bool){。。。
}我在从 嵌套在另一个UIViewController(vc1)中的UIViewController(vc2) 我是这样解决的:
[vc1 addChildViewController:vc2]
完成此操作后,我可以从vc2显示UIAlertController,而不显示任何错误消息。如果此错误发生在弹出视图控制器中,则需要调用代码,以便使用委派直接从父视图显示警报控制器。例如,在父视图控制器中:
-(void) showAlertError: (YourClass *) whateverParameter {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Your Title"
message:@"Your message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
});
}
在你的孩子看来:
- (IBAction)btnDone:(id)sender{
[self.delegate showAlertError:self];
}
没有一个答案对我有帮助。这里是我用来解决这个问题的代码
let topViewController = (self.navigationController?.viewControllers.last)! as UIViewController
topViewController.presentViewController(secondView, animated: true, completion: nil)
希望这会对某人有所帮助:)请单击下面的链接以获取相同的问题:
我试图从
拆分视图控制器
中显示UIViewController
这就解决了我的问题:
self.view.window.rootViewController.present(yourViewController, animated: true, completion: nil)
虽然这可能回答了这个问题,但如果您能解释一下为什么会这样做,这将是一个更好的答案。此外,这简要显示了第一个视图控制器,这似乎是无意的。确认,2017年,swift 3,iOs 10,从侧边菜单打开邮件弹出窗口时问题相同,唯一可行的解决方案是委托给主VC。不过不需要分派。我在ViewDidAspect()中调用的可能是重复的,但这无助于@UIResponderI找到类似的解决方案