尝试使用以下代码呈现模态视图 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:
之前:
- 将主视图移出 View Controller 的子级:
- Remove 从 XIB 中删除 View Controller (没有必要,因为 File's Owner 应该已经属于它的 Class):
之后:
关于ios - 尝试呈现模态视图 Controller 时的 UIViewControllerHierarchyInconsistency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12434937/