尝试呈现模式视图控制器时 UIViewControllerHierarchyInconsistency [英] UIViewControllerHierarchyInconsistency when trying to present a modal view controller

查看:26
本文介绍了尝试呈现模式视图控制器时 UIViewControllerHierarchyInconsistency的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用以下代码呈现模态视图控制器

Trying to present a modal view controller with the following code

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>.'

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

This is an old project that I havent touched in months, wonder what could cause such an error?

推荐答案

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

This happened to me already twice in the newest Xcode release. In both cases I needed to make changes to the UIViewController's XIB file (In you case it would be MapViewController.xib:

之前:

  1. 将主视图移出视图控制器的子视图:
  2. 从 XIB 中移除视图控制器(这是没有必要的,因为文件的所有者应该已经是它的类了):
  1. Move main View out of View Controller's children:
  2. Remove View Controller from the XIB (it is not necessary since File's Owner should be of its Class already):

之后:

这篇关于尝试呈现模式视图控制器时 UIViewControllerHierarchyInconsistency的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆