“没有重复使用的表格单元的索引路径”的含义是什么? iOS 6/7中的消息? [英] What is the meaning of the "no index path for table cell being reused" message in iOS 6/7?

查看:76
本文介绍了“没有重复使用的表格单元的索引路径”的含义是什么? iOS 6/7中的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从开始用iOS 6(以及iOS 7)编译我的应用程序以来,我已经开始看到这条消息了。我知道UITableViews管理单元格的方式在iOS 6中是不同的,但我不需要修改我的代码以便继续工作。但我担心这条消息可能会指出一些我尚未看到的潜在问题。
任何人都可以放弃任何光线吗?

Since starting to compile my app with iOS 6 (and since also iOS 7) I've started seeing this message. I know that the way that UITableViews go about managing cells is different in iOS 6 but I haven't needed to modify my code for it to keep working. But I'm concerned this message may point to some potential issue that I'm not yet seeing. Can anyone shed any light?

推荐答案

我开始在iOS 7 beta的日志中显示此错误5开始,包括在iOS 7 GM / Release版本中,同时从未在iOS 6或早期的iOS 7测试版中的应用中发生过。经过大量的实验,我找到了原因:

I started to get this error showing up in the log from iOS 7 beta 5 onwards, including in the iOS 7 GM/Release build, whilst never having had it happen in my app in iOS 6 or the earlier iOS 7 betas. After a lot of experimenting I found the cause:

我使用 UITableViewCell 对象作为我的节头视图并返回它们在 tableView:viewForHeaderInSection:中。这似乎是常见的做法,特别是在iOS 5之后,当使用Interface Builder在StoryBoard中将部分标题视图设计为原型表视图单元变得容易时。

I was using UITableViewCell objects for my section header views and returning them in tableView:viewForHeaderInSection:. This appears to be common practice, especially since iOS 5 when it became easy to design a section header view as a prototype table view cell in a StoryBoard with Interface Builder.

我更改了我的应用程序,只使用常规 UIView 子类用于我的节头视图,错误消失了,更重要的是,我的表视图停止随机删除节标题!

When I changed my app to use just regular UIView subclasses for my section header views, the errors went away and, more importantly, my table view stopped randomly deleting section headers!

看来(自iOS 7 beta 5起) UITableView 在内部维护所有 UITableViewCell 其视图层次结构中的对象及其各自的索引路径。由于节标题(或页脚的表格视图标题)没有索引路径,如果对这些视图使用 UITableViewCell 对象,表格视图将会混淆当它找到一个没有索引路径的 UITableViewCell 时,会导致没有重复使用表格单元的索引路径错误,如果你运气不好,在表格视图中显示毛刺:

It would appear that (since iOS 7 beta 5) UITableView is internally maintaining a mapping of all the UITableViewCell objects in its view hierarchy and their respective index paths. Since a section header (or a table view header of footer) doesn't have an index path, if you use a UITableViewCell object for these views, the table view will get confused when it finds a UITableViewCell for which it doesn't have an index path, resulting in the "no index path for table cell being reused" error and, if you're unlucky, display glitches in your table view:

更新:如果您可以访问Apple Dev论坛,这里是关于它的主题(我是开始): https://devforums.apple.com/message/882042#882042

UPDATE: if you have access to the Apple Dev Forums, here's the thread about it (which I started): https://devforums.apple.com/message/882042#882042

正如该线程中所建议的那样,如果你不想重新计算多少,你可以在你的<$周围创建一个 UIView 包装器c $ c> UITableViewCell 并将其作为节标题视图返回。

As suggested in that thread, if you don't want to re-factor much, you can create a UIView wrapper around your UITableViewCell and return that as the section header view.

UIView *view = [[UIView alloc] initWithFrame:[cell frame]];
[view addSubview:cell];

return view;

请注意,这个包装 UIView AutoLayout和设备轮换方法不会很好,所以我建议您使用 UIView 子类来表示页眉和页脚单元格,而不是 UITableViewCell 子类,如答案的主要部分所述。

Note however that this "wrapper" UIView approach will not play well with AutoLayout and device rotation, so I suggest that you use a UIView subclass for header and footer cells, not a UITableViewCell subclass as explained in the main part of the answer.

这篇关于“没有重复使用的表格单元的索引路径”的含义是什么? iOS 6/7中的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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