【发布时间】:2015-05-19 07:47:13
【问题描述】:
目前我可以点击一个单元格并使用didSelectRowAtIndexPath 选择它。但是,我无法在点击时取消选择它。我希望切换这两个功能。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var selectedCell = tableView.cellForRowAtIndexPath(indexPath)!
selectedCell.backgroundColor = UIColor.purpleColor()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
- 我的
View Controller中有一个TableView。 -
dataSource和delegate已设置。 - 在
UIBuilder中为表格启用了多项选择。
【问题讨论】:
-
在这段代码中你想做什么?你得到当前点击的单元格,然后将 backgroundColor 设置为紫色。它的目的是什么,它是否有效?
-
是的,我得到了当前点击的单元格并将背景设置为紫色,它运行良好。现在,我正在尝试再次点击该单元格并将其取消选择为我选择它之前的方式。
标签: ios uitableview swift didselectrowatindexpath