Joh*_*ley 2 uitableview didselectrowatindexpath ios swift
目前我可以点击一个单元格并使用它来选择它didSelectRowAtIndexPath.但是,点击时我无法取消选择它.我希望切换这两个功能.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var selectedCell = tableView.cellForRowAtIndexPath(indexPath)!
selectedCell.backgroundColor = UIColor.purpleColor()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
TableView在我的View Controller.dataSource与delegate已经成立.UIBuilder为表格启用了多个选择.我本来可以发誓我曾经尝试过这个,但之后就没用了.
我决定使用两个函数..
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var selectedCell = tableView.cellForRowAtIndexPath(indexPath)!
selectedCell.backgroundColor = UIColor.purpleColor()
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
var deselectedCell = tableView.cellForRowAtIndexPath(indexPath)!
deselectedCell.backgroundColor = UIColor.clearColor()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11864 次 |
| 最近记录: |