我的单元格中有一个标签,我想在点击时显示/隐藏.我知道我必须从didSelectRowAtIndexPath中获取单元格的索引路径.但我不确定如何在特定单元格中显示/隐藏标签.
我可以在didSelectRowAtIndexPath中显示/隐藏它,还是有办法在cellForRowAtIndexPath中处理它然后更新它?
我做了一些研究,但我真的找不到很多东西.
以下是我到目前为止的所有内容:
var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1,inSection: 0) override func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) { selectedRowIndex = indexPath }
解决方法
以下是从索引路径到达单元格的方法:
let cell = tableView.cellForRowAtIndexPath(indexPath) as MyCustomCell cell.myTextLabel.hidden = true
此外,根据您的需要,您可能还想取消选择单元格.
tableView.deselectRowAtIndexPath(indexPath)