调用 ReloadData 时 UITableView 绘制问题 [英] UITableView Drawing Problems When ReloadData Is Called

查看:18
本文介绍了调用 ReloadData 时 UITableView 绘制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的项目"列表(最多 250 个条目),并且不断变化.该列表正在 UITableView 中显示.

我有一个轮询线程,它将下载一些新条目并将它们插入 SQLite DB.

当新条目到达时,我调用我的表视图数据源对象来更新它的数据集,它运行一个 SQL 查询并返回一个新的条目数组.

完成后,我在表格视图上调用 -reloadData.发生这种情况时,在 10 种情况下大约有 7 种情况下,表格视图绘制为空白(不显示单元格,只有表格的背景颜色可见),直到进行后续的 -reloadData 调用.触摸表格视图(滚动、选择单元格、任何会强制重绘的内容)将使其重新出现.

表格视图、它的 IBOutlet 指针和当前显示的单元格在我看到空白绘图错误时都是有效的,所以我相当有信心它们没有被释放.

这几天我一直在尝试调试它,但它真的开始让我陷入困境.

在这方面的任何帮助都会非常棒,谢谢.

解决方案

如果你做一个 [ myTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO] 会有帮助吗?p>

如果您不从主线程操作您的 GUI 更新,则可能会出现您提到的问题.

I have a pretty large list of 'items' (up to 250 entries) which is constantly changing. The list is being displayed in a UITableView.

I have a polling thread that will download some new entries and insert them into a SQLite DB.

When new entries have arrived, I call to my table view data source object to update its data set, which runs a SQL query and returns a new array of entries.

After this is complete, I call -reloadData on the table view. When this happens, in about 7 out of 10 cases, the table view draws blank (no cells are displayed and only the background colour of the table is visible) until a subsequent -reloadData call is made. Touching the table view (scrolling, selecting a cell, anything that will force a redraw) will make it reappear.

The table view, its IBOutlet pointer and it's currently displayed cells are all valid at the times I see the blank drawing bug, so I'm fairly confident that they're not being released.

I've been trying to debug this for a few days now and it's really beginning to drive me up the wall.

Any help on this would be freaking awesome, thanks.

解决方案

Will it help if you do a [ myTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO] ?

The problem you mentioned can arise if you do not action your GUI updates from the main thread.

这篇关于调用 ReloadData 时 UITableView 绘制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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