man*_*anu 2 uitableview didselectrowatindexpath swift
有没有办法获取选择行的部分的实例?可以获取节的索引,所选单元格的索引,所选单元格的实例..但是此节的实例?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow // index path of selected cell
let headerCellIndex = indexPath!.section // index of selected section
let headerCellName = ????? // instance of selected section
let cellIndex = indexPath!.row // index of selected cell
let cellName = tableView.cellForRowAtIndexPath(indexPath!) // instance of selected cell
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
Ted*_*ink 10
这对我来说总是很好.我总是打开它,也可以选择我分配给它的类,以确保我有正确的单元格类型.在这个例子中,我有MyTableViewCell,但它当然可以是任何东西.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? MyTableViewCell {
print(cell.label.text!)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13092 次 |
| 最近记录: |