【发布时间】:2016-06-22 05:16:43
【问题描述】:
有没有办法获取选择行的部分的实例?可以获取section的index,选中cell的index,选中cell的instance..但是这个section的instance呢?
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
}
谢谢。
【问题讨论】:
-
tableview 加载时如何插入部分的名称?
-
String(content[section].sectionName)这也适用于didSelectRowAtIndexPath-method..但是没有办法以某种方式获取节的名称,类似于获取所选单元格的名称? -
内容是数组/对象吗?
-
在 didSelectRow 中你为什么不试试...
var secName = content[indexPath.section].sectionName -
没有部分实例,您不应该从单元格中获取标签文本 - 始终从您的数据模型中获取数据,只获取单元格实例以便您可以更新它
标签: swift uitableview didselectrowatindexpath