我喜歡在用戶觸摸blue
中的單元格時突出顯示錶格單元格中的行,然後當用戶選擇操作按鈕時,我希望它將其更改爲gray
顏色當按下提示控制器動作按鈕時突出顯示錶格單元格
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var newCell = tableView.cellForRow(at: indexPath)!
newCell.backgroundColor = UIColor.blue
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let okButton = UIAlertAction(title: "Ok", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
var newCell = tableView.cellForRow(at: indexPath)!
newCell.backgroundColor = UIColor.gray
})
let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in
print("Cancel button tapped")
var newCell = tableView.cellForRow(at: indexPath)!
newCell.backgroundColor = UIColor.gray
})
alertController.addAction(okButton)
alertController.addAction(cancelButton)
present(alertController, animated: true, completion: nil)
}
func tableView(_ tableView: UITableView, didhighlightRowAt indexPath: IndexPath) {
var newCell = tableView.cellForRow(at: indexPath)!
newCell.backgroundColor = UIColor.clear
}
我做到這一點,它凸顯了細胞在white
色彩和動作按鈕被點擊之後,它仍然保持white
但是當我點擊另一個單元格,前一小區轉彎和保持gray
1.我的細胞是清晰的彩色2.當用戶敲擊它們變成藍色3.當用戶按動作按鈕,他們變成灰色,保持灰色。我希望你現在清楚。對不起,我感到困惑 – Coder221
我現在明白了:)我最近的編輯應該做的伎倆。關鍵是引用cellForRow中的「被選中」狀態來確定背景顏色。 – Lytic
欣賞響應。你有沒有關於你正在說話的步驟的簡短示例代碼,這將對我有很大幫助。 – Coder221