UITableView随机消失的细胞 [英] UITableView has randomly disappearing cells

查看:89
本文介绍了UITableView随机消失的细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的UITableView,它使用NSArray航班预订,每次预订显示一个单元格。最近客户提出了一个问题(我偶尔会偶尔复制),其中一些单元格被完全隐藏。它们的空间在那里,但它们应该存在差距。

I have a fairly simple UITableView which uses an NSArray of flight bookings, and displays one cell per booking. Recently customers have raised an issue (which I can only very occasionally reproduce) whereby some of the cells are completely hidden. The space for them is there, but there's just a gap where they should be.

该表有一个页眉和页脚所以我可以看到间隙(它不仅仅是那个元素较少)。

The table has a header and footer so I can see the gaps (it's not just that there are less elements).

此处的示例截图: http://myflightsapp.com/images/missing-cells.png

这实际上是间歇性的,因为如果我重新启动应用程序,问题就出现了问题消失了。

It really is intermittent, because if I restart the app, the issue goes away.

我尝试用一​​个非常简单的2衬里替换cellForRowAtIndexPath,只返回带有文本标签的完全标准的UITableViewCell,它显示相同的问题,所以对我来说,排除Nib / Custom类是个问题。

I've tried replacing cellForRowAtIndexPath with a very simple 2 liner to just return a completely standard UITableViewCell with a text label, and it displays the same issue, so for me that rules out the Nib/Custom class being the issue.

heightForRowAtIndexPath总是返回一个常量,所以它没有错误地显示零高度行。

The heightForRowAtIndexPath always returns a constant, so it's not showing a zero height row by mistake.

表中只有1个部分。

我把调试放在numberOfSectionsInTableView方法中,它是alwa ys返回正确的数字(在这个例子中是2)

I've put debug in the numberOfSectionsInTableView method and it's always returning the correct number (2 in this example)

我把调试放在cellForRowAtIndexPath中,我从中学到了:
1)如果我将表格视图拖得足够高(所以单元格从屏幕上消失)并再次放开,在问题显示的情况下,当表格滚动回视图时,它不会再次调用cellForRowAtIndexPath来重新绘制单元格,但是当问题不存在时(即单元格都是可见的)它会为每个单元格再次调用cellForRowAtIndexPath。

I've put debug in the cellForRowAtIndexPath, from which I've learnt: 1) If I drag the table view up high enough (so the cells disappear off the screen) and let go again, in circumstances when the issue is showing, it doesn't call cellForRowAtIndexPath again to try and redraw the cells when the table scrolls back into view, but when the issue is not there (i.e. the cells are all visible) it does call cellForRowAtIndexPath again for each cell.

2)任何单元格都没有'hidden'属性为真。

2) At no point do any of the cells have the 'hidden' property true.

从其他地方添加调试(例如临时按钮)我可以手动调用未显示的单元格的cellForRowAtIndexPath方法,并返回看似有效的单元格。

From adding debug elsewhere (e.g. a temporary button) I can manually invoke the cellForRowAtIndexPath method for a cell which is not displayed, and it returns what seems to be a valid cell.

所以我的问题是,什么可能导致我看到的问题?我已经没有地方可以调试以查看问题所在。

So my question is, what can cause the issue I'm seeing? I'm running out of places to put debug to see where the issue may be.

会非常感谢任何帮助 - 我错过了什么?

Would massively appreciate any help - what am I missing?

推荐答案

在Apple Dev技术支持的帮助下......我已经解决了。为了其他任何人遇到它的好处,原因是我不小心调用方法从辅助线程而不是主线程重新加载表。

With help from Apple Dev Technical Support... I've resolved it. For the benefit of anyone else that comes across it, the reason was that I was accidentally calling the methods to reload the table from a secondary thread instead of on the main thread.

为了解决这个问题,我使用了以下

To resolve, I used the following

[self performSelectorOnMainThread:@selector(refreshMethod) withObject:nil waitUntilDone:YES];

到目前为止一切顺利。

And so far so good.

这篇关于UITableView随机消失的细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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