我的項目中有一個UITableView控制器。所以我做了一個UITableViewCell設置喜歡這裏:UITableViewCell的背景設置在滾動上重置
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = "Section: \(indexPath.section). Row: \(indexPath.row)."
if indexPath.row % 2 == 1 {
cell.backgroundColor = UIColor.gray
}
return cell
}
我希望我的tableview的細胞是灰色的,如果他們的指數是不是整除2.
時出現的tableview,一切都是完美的!但是當我上下滾動時,單元格開始將它們的顏色變成灰色。
所以最後我的所有細胞都是灰色的。
下面是一些圖片:
非常感謝)它是那麼容易!):d –
@AlexVihlayev沒問題的伴侶。 :) –