You are right, cell configuration can (in theory) be done in both methods.
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.
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:
).
There's one notable exception: when you are using a storyboard and static cells (instead of cell prototypes), you can't do anything useful in cellForRowAtIndexPath:
(because dequeueReusableCellWithIdentifier:
returns nil
), so you have to do configuration in willDisplayCell:forRowAtIndexPath:
, viewWillAppear:
or other methods.
@NSDeveloper: you're right. Thanks for the hint.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…