uitable的交替背景色

注:

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]];
  }
 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章