注:
uitable在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
设定颜色,是无效的。
正确设定颜色的位置是:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
示例=========================================================================================
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView==main_friend_table) {
if(indexPath.row % 2 == 1){
[cell setBackgroundColor:[UIColor grayColor]];
}
else{//indexPath.row % 2 == 0
[cell setBackgroundColor:[UIColor whiteColor]];
}
}
}

本文详细介绍了如何在UITableView中正确地使用`willDisplayCell:forRowAtIndexPath:`方法来设置单元格的颜色,避免了直接在`tableView:cellForRowAtIndexPath:`方法中进行颜色设置导致的无效操作。

2110

被折叠的 条评论
为什么被折叠?



