I would like to get the cell frame
at tableView:cellForRowAtIndexPath:
in order to position and size the views that I want to add to UITableViewCell
's contentView
. But there self.frame
is always (0, 0, 320, 44)
.
I know you can get the right frame
in layoutSubviews
(thanks to this answer), but if I add the subviews there it would be done every time the cell is reused, not only once like in the "official" example at Programmatically Adding Subviews to a Cell’s Content View.
In that example they add some views using hardcoded frames like:
mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)];
I guess that example is outdated, since they should use constraints, or at least calculate the size of subviews using the actual cell frame
(which may be impossible to get at that point indeed).
Note: this reminds me of the view holder design pattern used in Android.