尝试使用以下代码呈现模态视图 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:
在此之前:
之后:
关于ios - 尝试呈现模态视图 Controller 时的UIViewControllerHierarchyInconsistency,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12434937/