我有一个简单的 tableView,我的想法是,当用户点击一个单元格警报时会弹出 - 但出于某种原因,我必须点击两次才能显示警报,这是为什么? 我的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:
IndexPath) {
let employee = employees[indexPath.row]
let alertView = UIAlertController(title: "Stämpelklocka",
message: employee.firstName + " " + employee.lastName,
preferredStyle: .alert)
let cancel = UIAlertAction(title: "Avbryt", style:
.destructive) { (action) in
}
let accept = UIAlertAction(title: "Stämpla Ut?", style:
UIAlertActionStyle.default) { (action) in
}
alertView.addAction(cancel)
alertView.addAction(accept)
present(alertView, animated: true, completion: nil)
}
最佳答案
你必须在这里取消选择它
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:
IndexPath) {
let employee = employees[indexPath.row]
let alertView = UIAlertController(title: "Stämpelklocka",
message: employee.firstName + " " + employee.lastName,
preferredStyle: .alert)
let cancel = UIAlertAction(title: "Avbryt", style:
.destructive) { (action) in
}
let accept = UIAlertAction(title: "Stämpla Ut?", style:
UIAlertActionStyle.default) { (action) in
}
alertView.addAction(cancel)
alertView.addAction(accept)
present(alertView, animated: true, completion: nil)
// deselect
tableView.deselectRow(at: indexPath, animated: false)
}
关于swift - 为什么我需要在 UITableView 中的单元格上点击两次才能显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50832141/