I've read quite a few different ways to tackle the problem of setting the UITableViewCell color. Was just after a quick confirmation that the code/approach below is fine re a best practice / performance point of view?
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
Some notes/questions associated with this:
You are correct, this is the way to do it. The UITableViewCell
documentation even explicitly states that background colors should be set in tableView:willDisplayCell:forRowAtIndexPath:
as opposed to tableView:cellForRowAtIndexPath:
. Don't fear, you are on the right path sir.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.