【发布时间】:2016-10-08 23:01:01
【问题描述】:
当用户触摸blue 中的单元格时,我喜欢突出显示tableview 单元格中的行,然后当用户选择操作按钮时,我希望将其更改为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
【问题讨论】:
标签: ios swift uitableview uiactionsheet