我创建了一个自定义UITableViewCell
(以及故事板设计器中用于布局的 XIB)。我了解父表视图如何通过触发通知单元格选择didSelectRowAtIndexPath
,但我似乎无法弄清楚如何捕获单元格本身内的单元格选择。有人能在这里指出正确的方向吗?我使用 XCode 8 和 Swift 2。谢谢!
这是我的简单自定义单元格类,其中包含在选择单元格时处理的存根函数:
class MyCustomCell: UITableViewCell {
func didSelect(indexPath: NSIndexPath ) {
// perform some actions here
}
}
你能做的就是倾听didSelectRowAtIndexPath
在 UITableView 上,然后调用单元格中的函数。这是一个例子:
class MyCustomCell: UITableViewCell {
func didSelect(indexPath: NSIndexPath) {
// perform some actions here
}
}
然后,在你的didSelectRowAtIndexPath
:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? MyCustomCell {
cell.didSelect(indexPath: indexPath)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)