gpt4 book ai didi

ios - 尝试呈现模态视图 Controller 时的 UIViewControllerHierarchyInconsistency

转载 作者:IT老高 更新时间:2023-10-28 11:48:29 25 4
gpt4 key购买 nike

尝试使用以下代码呈现模态视图 Controller

MapViewController *mapView = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
mapView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:mapView animated:YES];
[mapView release];

不断收到以下错误..

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UIView: 0x1ed815a0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x1ed81600>> is associated with <UIViewController: 0x1ed835a0>. Clear this association before associating this view with <MapViewController: 0x1dd947c0>.'

这是一个我好几个月没碰过的老项目,不知道是什么导致了这样的错误?

最佳答案

这在我最新的 Xcode 版本中已经发生过两次。在这两种情况下,我都需要对 UIViewController 的 XIB 文件进行更改(在您的情况下,它将是 MapViewController.xib:

之前:

enter image description here

  1. 将主视图移出 View Controller 的子级:
  2. Remove 从 XIB 中删除 View Controller (没有必要,因为 File's Owner 应该已经属于它的 Class):

之后:

enter image description here

关于ios - 尝试呈现模态视图 Controller 时的 UIViewControllerHierarchyInconsistency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12434937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com