问题描述
正如问题的标题所提到的:"cellForRowAtIndexPath
" 和 "willDisplayCell
: forRowAtIndexPath
:" 有什么区别?`
Just as the question's title mentions:What's the difference between "cellForRowAtIndexPath
" and "willDisplayCell
: forRowAtIndexPath
:"?`
我认为可以在 cellForRowAtIndexPath
或 willDisplayCell: forRowAtIndexPath:
" 中完成单元格配置!
I think cell configuration can be done either in cellForRowAtIndexPath
or willDisplayCell: forRowAtIndexPath:
"!
推荐答案
你说得对,单元格配置(理论上)可以在两种方法中完成.
You are right, cell configuration can (in theory) be done in both methods.
然而,几乎所有的UITableView
都有一个实现了cellForRowAtIndexPath:
的数据源(它是协议中的必需方法).另一方面,willDisplayCell:forRowAtIndexPath:
(这是委托的一个方法,不是数据源)是可选的.
However, almost all UITableView
have a data source which implements cellForRowAtIndexPath:
(it is a required method in the protocol). On the other hand, the willDisplayCell:forRowAtIndexPath:
(which is a method of the delegate, not the data source) is optional.
由于配置单元格通常取决于您想要显示的数据,cellForRowAtIndexPath:
是迄今为止进行单元格配置最常见的地方.(我什至不记得使用了 willDisplayCell:forRowAtIndexPath:
).
As configuring a cell is usually dependent on the data you want to show, cellForRowAtIndexPath:
is by far the most common place to do cell configuration. (I can't even remember using willDisplayCell:forRowAtIndexPath:
).
@NSDeveloper:你说得对.谢谢提示.
@NSDeveloper: you're right. Thanks for the hint.
这篇关于iOS UITableView:“cellForRowAtIndexPath"和“cellForRowAtIndexPath"有什么不同?和“willDisplayCell:forRowAtIndexPath:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!