何时调用 cellForRowAtIndexPath 方法? [英] When is cellForRowAtIndexPath method called?
问题描述
这个方法具体是什么时候调用的?假设一次我有 4 个 tableview 单元格在屏幕上可见,那么将调用多少个单元格.另外,如果一个单元格是部分可见的,那么在这种情况下是否也会为下一个单元格调用该方法?
When exactly is this method called ? Suppose at a time I have 4 of my tableview cells visible on the screen then for how many cells will this method be called. Also, what if a cell is partially visible, will the method be called for the next cell as well in this case ?
附言我没有被困在任何地方,所以显示一些代码没有任何意义.这只是一个基本的疑问.
P.S. I am not stuck anywhere, so showing some code doesn't make any sense. Its just a fundamental doubt.
推荐答案
我能给你的最简单的解释是——cellForRowAtIndexPath
,当一个单元格即将显示在屏幕上时会调用你的视图控制器.所以这个条件在
The most simple explanation I can give you is - cellForRowAtIndexPath
, will call when a cell is about to be shown in the screen of your view controller. So this condition is valid whenever
- Tableview 正在重新加载
[tableview reloadData]
,因此每个单元格都将再次出列/填充. - 每次您滚动并即将看到一个新单元格时.UITableview 使用离开视图的单元格(可见区域),并使用该特定单元格填充新数据.
- 在
numberOfRows
之后.如果您的视图控制器在故事板中有一个 tableview.这在viewDidLoad
中调用,因为当 VC 检查故事板中的 tableview 时,它会先调用强制 tableview 数据源numberOfRows
然后它会调用cellForRowAtIndexpath代码>,该时间量,屏幕中可见的单元格数量.
- Tableview is being reloaded
[tableview reloadData]
, thus every cell will be dequeued/ populated again. - Every time you scroll and are about to see a new cell. UITableview uses the cell that is going out of the view (visible area), and uses that particular cell to populate new data.
- After
numberOfRows
. If your View Controller has a tableview in the storyboard. This is called inviewDidLoad
as when the VC inspects a tableview in the storyboard, it will call the mandatory tableview datasourcenumberOfRows
first and then it will callcellForRowAtIndexpath
, that amount of time, the number of cells visible in the screen.
希望能解决您的困惑.
这篇关于何时调用 cellForRowAtIndexPath 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!