谁能告诉我如何在 UISwitch 的操作函数内获取其类(更具体地说是 uitableViewCell )内单元格的索引。 我做了以下事情..
var cell = sender.superview?.superview as UITableViewCell
var table: UITableView = cell.superview as UITableView
let indexPath = table.indexPathForCell(cell)
但随后它崩溃了。 解决办法是什么?
最佳答案
试试这个:
假设您在 cell
自定义类中有一个 UISwitch *cellSwitch
对象
在cellForRowAtIndexPath
中:
cell.cellSwitch.tag = indexPath.row
在此开关的 IBAction
中:
let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0)
关于xcode - 快速获取 UITableViewCell 内单元格的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32703486/