when subclassing UITableViewCell to define a complete custom cell what style to set? UITableViewCellStyleDefault? Actually I don’t need neither the label or the imageView, would they be allocated the same?
So when attaching my custom views to the UITableViewCell subclass, is it better to add to self, or to self.contentView?
And is it ok to do some quartz drawing in drawRect in the UITableViewCell subclass (Like background) ?
Thanks
Since you are not using any of the pre-defined UILabel or UIImageView subviews of UITableViewCell, it doesn’t really matter. I just use
UITableViewCellStyleDefault. I do not know for sure if the UILabels or the UIImageView are allocated or not. However, since there is no way to explicitly tell the UITableViewCell not to create those subviews, I wouldn’t worry about it. Even if they are created, you aren’t using them so drawing the cell will not be any slower, and since cells are reused as you scroll through the table, allocating just a few extra objects once is not going to affect your overall table view performance.All of the content should be put in the UITableViewCell
contentView. This will ensure that the contents behave properly when the UITableView has an index on the right or if the UITableView (or UITableViewCell) go into editing mode.The recommended approach is for the background to be placed in the UITableViewCell
backgroundViewproperty. So I would not recommend doing any drawing in the UITableViewCell subclass itself. Just use thecontentView,backgroundView, andselectedBackgroundViewproperties. You can create a simple UIView subclass and just set that as thebackgroundViewof the UITableViewCell, if you like.