UITableView:cellForRowAtIndexPath继续被调用 [英] UITableView :cellForRowAtIndexPath Continues being called

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

问题描述

我有一个UITableView控制器和一个UITableView。我使用委托等设置了所有内容,并且填充正常。我注意到一个小错误但是使用以下方法:

I have a UITableView Controller and a UITableView. I have everything set up using the delegates etc, and it populates fine. I notice a small bug however with the following method:

:cellForRowAtIndexPath

:cellForRowAtIndexPath

我注意到这个方法是每次我滚动桌子时都会不停地打电话。即使在填充表后,它仍会继续调用。基本上,一个单元格移出视图,当它返回视图时,它再次调用它。我让NSLog打印出该方法中的单元格内容,这就是我知道它继续调用的方式。

I am noticing that this method is continually called every time I scroll the table. Even after the table is populated, it continues to call. Basically, a cell moves out of view, when it comes back in view, it is calling it again. I had NSLog print out the cell contents within that method, which is how I know it continues to call.

该函数是否应该每个单元调用一次,以填充它,然后完成?

Should that function not just call once per cell, to populate it, then be done?

推荐答案

不。每次需要一个单元格时都会调用它,每次渲染一个单元格时都需要一个单元格。

Nope. That's called every time a cell is needed, and a cell is needed every time one is rendered.

UITableView是一个非常聪明的小动物。它实际上只保留它显示的单元格,加上一两个或更多的缓存。当滚动一个没有打开的单元格的时候,可以从缓存中询问一个单元格,如果有单元格,它将被重用。

UITableView is a very clever little critter. It literally keeps only the cells it's displaying, plus a cache of literally two or three more. When the time comes to scroll a cell on that wasn't on, it can be asked for a cell from the cache, and if there is one, it gets reused.

这样可以在UITableView中显示巨大的数据集,因为内存中没有大量的单元格,只有屏幕上的单元格和小缓存。

This way HUGE data sets can be displayed in a UITableView, because there really aren't a large number of cells in memory, only the ones on the screen and a small cache.

这篇关于UITableView:cellForRowAtIndexPath继续被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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