【问题标题】:Ignoring Warning about detached ViewControllers忽略有关分离的 ViewController 的警告
【发布时间】:2014-11-17 18:28:14
【问题描述】:

我正在从 Storyboard 中加载 ViewController,如下所示:

SSContentViewController* contentViewController =
    [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]
    instantiateViewControllerWithIdentifier:@"settingsViewController"];

并将其添加到我的 ViewController 数组中:

[self.viewControllers addObject:contentViewController];

在 SettingsViewController 中,我有一个 segue,它提供了一个模态视图控制器。如果我执行这个 segue,我会得到一个“不鼓励在分离的视图控制器上显示视图控制器”-控制台输出中的警告。

但这并没有错。一切都按预期工作。忽略此警告是否安全?

编辑:

问题是我执行 segue 的 ViewController 被添加到我的 RootViewController 中:

[rootVC.view addSubview:viewController.view];

所以我知道它是分离的。但即使有这个警告,事情也会正常工作,不会产生视觉错误等......

【问题讨论】:

  • 如果您发现以下答案有用,请接受它。谢谢。
  • 但是并没有解决问题...

标签: ios objective-c uiviewcontroller storyboard warnings


【解决方案1】:

您实际上应该使用 presentViewcontroller 和 dismissviewcontroller 来避免这种情况。

而不是添加使用:

[self.view.window.rootViewController presentViewController:contentViewController animated:YES completion:nil];

并从模型视图中使用以下来关闭:

[self dismissViewControllerAnimated:YES completion:nil];

编辑 01: 对于帧率下降,请尝试以下:

 [picker dismissViewControllerAnimated: YES completion:^{

        [self performSelector:@selector(reinit) withObject:nil afterDelay:2];

    }];

【讨论】:

  • 已更新,请立即尝试。
  • 我当然明白!而且,是的,这行得通。但它让我遇到了另一个问题。在 ViewController 被关闭后,帧率从 60 FPS 下降到大约 40 FPS 和滚动,其他一切都不再流畅了。如果我以旧方式执行此操作,我仍然会收到该警告,但它不会影响渲染性能。我正在后台使用 UIVisualEffectView,这似乎是 FPS 下降的问题 - 在分离的视图控制器上显示 ViewController 时不会发生这种情况。
  • 由于presentViewController,一般不会发生这种情况。您能否确认您没有留下任何渲染块仍处于打开状态。顺便说一句,你使用 segue 吗?在这种情况下,请尝试使用 (performSegueWithIdentifier)
  • 使用 (performSegueWithIdentifier) 会导致同样的问题。在 RootViewController 上没有警告,但它会大大降低 FPS。在分离的 ViewController 上,我收到该警告,但 FPS 在 (dismissViewControllerAnimated) 之后不受影响
  • 嗯,所以这种帧速率下降是连续的还是只是在关闭视图控制器时?如果是这种情况,您应该尝试在我的答案中进行编辑。
猜你喜欢
  • 2019-08-25
  • 2016-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-10
  • 2010-10-07
  • 2016-10-03
  • 2012-01-14
相关资源
最近更新 更多