按钮上的iOS6 UIViewControllerHierarchyInconsistency单击 [英] iOS6 UIViewControllerHierarchyInconsistency on Button click

查看:90
本文介绍了按钮上的iOS6 UIViewControllerHierarchyInconsistency单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 6 iPad中遇到问题

I facing issue in iOS 6 iPad


  1. 点击按钮 - >用UITable打开popover

  2. 选择一行 - > modalviewcontroller打开。

  3. 关闭modalviewcontroller(它工作正常)

  4. 然后再次单击按钮,应用程序崩溃按钮点击(第1步)

  1. On button click -> open popover with UITable
  2. On select a row -> modalviewcontroller open.
  3. dismiss modalviewcontroller (it works fine)
  4. Then again click on button, app crash on button click (1st step)

此问题仅适用于iOS 6.它适用于iOS 5,iOS 4.3

this issue is only in iOS 6. It works fine in iOS 5, iOS 4.3

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UITableView: 0xb847400; frame = (0 0; 185 104); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0xa469e50>; layer = <CALayer: 0xa469f00>; contentOffset: {0, 0}> is associated with <UIViewController: 0xa462f60>. Clear this association before associating this view with <UIViewController: 0xa5dac40>.'
*** First throw call stack:
(0x2769012 0x1d0be7e 0x2768deb 0xca1309 0xd385ac 0xd34a90 0x69b19 0x1d1f705 0xc56920 0xc568b8 0xd17671 0xd17bcf 0xd16d38 0xc8633f 0xc86552 0xc643aa 0xc55cf8 0x29a2df9 0x29a2ad0 0x26debf5 0x26de962 0x270fbb6 0x270ef44 0x270ee1b 0x29a17e3 0x29a1668 0xc5365c 0x24ca 0x23d5)
libc++abi.dylib: terminate called throwing an exception

添加代码

listTable.frame = CGRectMake(0, 0, listWidth, listItemHeight*[listArray count]-1);
UIViewController* popoverContent = [[UIViewController alloc] init];
popoverContent.view = listTable;
popoverContent.contentSizeForViewInPopover = CGSizeMake(listWidth, listItemHeight*[listArray count]);
listPopOver = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[listPopOver setDelegate:self];
[listPopOver setPopoverContentSize:listTable.frame.size];
[listPopOver presentPopoverFromRect:self.frame inView:self.superview permittedArrowDirections:arrowDirection animated:YES];
[listTable reloadData];
[popoverContent release];


推荐答案

更密切地检查您的例外情况:

Check out your exception more closely:

'UIViewControllerHierarchyInconsistency', reason:
'A view can only be associated with at most one view controller at a time!
View UITableView: 0xb847400; frame = (0 0; 185 104); clipsToBounds = YES;
autoresize = W+H; gestureRecognizers = NSArray: 0xa469e50; layer = CALayer: 0xa469f00;
contentOffset: {0, 0} is associated with UIViewController: 0xa462f60.
Clear this association before associating this view with UIViewController: 0xa5dac40.'

具体来说:

A view can only be associated with at most one view controller at a time!
View UITableView: 0xb847400
is associated with
UIViewController: 0xa462f60. 
Clear this association before associating this view with 
UIViewController: 0xa5dac40.

这意味着你有一个视图控制器,它是 .view 属性已设置为listTable对象。然后,在不破坏该关联的情况下,您使用另一个视图控制器并尝试将其 .view 属性设置为listTable对象。这违反了视图层次结构规则,Apple在iOS 6.0中的执行程度更高,现在它会引发异常并导致应用程序崩溃。

What this means is that you had a view controller, and it's .view property was set to your listTable object. Then, without destroying that association, you took another view controller and tried to set its .view property to the listTable object. This is a violation of the view hierarchy rules, which Apple is enforcing more heavily as of iOS 6.0, to the point where it now throws an exception and crashes your app.

所以这里真正的问题是你使用相同的listTable对象和两个视图控制器,特别是 popoverContent 。这意味着当您的代码第二次执行时,旧的popoverContent仍然存在,这就是为什么它在第二次运行而不是第一次运行时崩溃的原因。我猜想,在尝试创建新的popover之前,你的代码不会完全解除分配和销毁你的旧popover;如果你确定发生这种情况你可能会没事。

So the real problem here is that you are using the same listTable object with two view controllers, specifically popoverContent. This means that your old popoverContent is still in existence when your code executes a second time, which is why it crashes on the 2nd run and not the first. I would guess that somehow your code is not fully deallocating and destroying your old popover before the new one is trying to be created; if you make sure this happens you might be fine.

我还注意到,显然,你对两个弹出窗口使用相同的listTable。你是否想懒洋洋地为每个popover创建这个listTable而不是保留它?

I also notice that, apparently, you are using the same listTable for both popovers. Do you perhaps want to lazily create this listTable for each popover instead of keeping it around?

如果你想更多地研究一下,你可以在你的代码中设置一个断点使用 po 命令打印不同视图和视图控制器的描述,以查看哪些十六进制地址与随后出现在您的异常中的十六进制地址相匹配,并获取有关该地址的更多信息。问题。或者,您甚至可以直接使用十六进制地址打印描述: po 0xa469e50 例如(可能必须对其进行类型转换)。

If you want to investigate things more, you can set a breakpoint in your code and print descriptions of your different views and view controllers, using the po command, to see what hex addresses match the ones that will subsequently appear in your exception, and get more information about the problem. Or, you can even print descriptions using the hex addresses directly: po 0xa469e50 for example (may have to typecast it, though).

除此之外,你还没有为某人提供足够的代码来查看它并说明问题是什么:)但上面的内容可以帮助你解决问题。

Other than that, you haven't really provided enough code for someone to just look at it and say what the problem is :) But the above should help you work it out.

这篇关于按钮上的iOS6 UIViewControllerHierarchyInconsistency单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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