不要在TableView中更改背景颜色contentView

时间:2017-06-22 07:21:51

标签: ios swift uitableview

if indexPath.row == 2 {
    cell.contentView.backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
} else{ 
    cell.backgroundColor = UIColor.white
}

不使用cellForRowAtIndexPathwillDisplayCellsAtIndexPath方法。

2 个答案:

答案 0 :(得分:0)

如果您想更改单元格使用public static void main(String[] args) { int num = Math.max(1,Integer.parseInt(args[0])); char[][] buffer = new char[num * 2][num * 2]; // The Buffer is needed writeQ1(buffer, num); writeQ2(buffer, num); writeQ3(buffer, num); writeQ4(buffer, num); printBuffer(buffer); } // With a buffer, this method is needed public static void printBuffer(char[][] buffer) { for (char[] cs : buffer) { for (char c : cs) { if (c == 0) { System.out.print(' '); } else { System.out.print(c); } } System.out.println(); } } // The next methods can be refactored! public static void writeQ1(char[][] buffer, int num) { for (int i = 0; i <= num; i++) { for (int j = 0; j < i; j++) { buffer[i][j + num] = '*'; } } } public static void writeQ2(char[][] buffer, int num) { for (int i = 0; i <= num; i++) { for (int j = 0; j < i; j++) { buffer[i][j + (num - i)] = '*'; } } } public static void writeQ3(char[][] buffer, int num) { for (int i = 0; i <= num; i++) { for (int j = 0; j < i; j++) { buffer[2*num - i][j + (num - i)] = '*'; } } } public static void writeQ4(char[][] buffer, int num) { for (int i = 0; i <= num; i++) { for (int j = 0; j < i; j++) { buffer[2*num - i][j + num] = '*'; } } } 的背景颜色。

但如果您仍想使用cell.backgroundColor,请务必向红色,绿色和蓝色提供contentView.backgroundColor值。只需将float替换为cell.contentView.backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)

即可

答案 1 :(得分:0)

如果您对单元格的内容视图有其他观点,则无论如何都不会显示内容视图背景。