ios - 点击 UITableView Cell 时隐藏标签

标签 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
}

最佳答案

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

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

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

tableView.deselectRowAtIndexPath(indexPath)

关于ios - 点击 UITableView Cell 时隐藏标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425302/

相关文章:

ios - 以编程方式自动布局不起作用

ios - Swift 分派(dispatch)到子类扩展中的重写方法

c++ - 组合 2 个函数时 Xcode 出错

iphone - UITableViewCell/UISegmentedControl 边框问题

swift - 如何正确匹配自定义 View 的框架与 TableViewCell 框架?

ios - 仅收藏 View 滚动项目

ios - 无法停止录音机

ios - 如何从应用程序委托(delegate)获取打开的 View

ios - 无法禁用 UITableView 分组中部分的页脚

ios - 如何在 Xcode 调试中使用 "PLCrashreporter"