点击UITableView Cell时隐藏标签

时间:2014-10-17 12:44:04

标签: ios xcode uitableview swift

我的单元格中有一个标签,我想在点击时显示/隐藏。我知道我必须从didSelectRowAtIndexPath内获取从中挖掘的单元格的索引路径。但我不确定如何在那个特定的单元格中显示/隐藏标签。

我可以在didSelectRowAtIndexPath内显示/隐藏它,还是有办法在cellForRowAtIndexPath中处理它然后更新它?

我对此做了一些研究,但我真的找不到很多。

到目前为止,这是我所拥有的一切:

var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1, inSection: 0)

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    selectedRowIndex = indexPath
}

1 个答案:

答案 0 :(得分:11)

以下是从索引路径到达单元格的方法:

let cell = tableView.cellForRowAtIndexPath(indexPath) as MyCustomCell
cell.myTextLabel.hidden = true

此外,根据您的需要,您可能还想取消选择该单元格。

tableView.deselectRowAtIndexPath(indexPath)