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

查看:166
本文介绍了尝试呈现模态视图控制器时的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];

继续收到以下错误..

Keep getting the following error..

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

BEFORE:


  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天全站免登陆