0

有没有办法隐藏所有单元格的字幕,直到您选择一个单元格 - 然后它只显示该单元格的字幕?我尝试了以下代码 - 它成功隐藏了所有字幕,但在我选择单元格时无法显示:

if cell.selected {
        cell.detailTextLabel?.hidden = false
    } else {
        cell.detailTextLabel?.hidden = true
    }

谢谢你的帮助。

编辑 2 - 我最终在我的 didSelectRowAtIndexPath 中这样做了:

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

    for cell in tableView.visibleCells() {
        cell.detailTextLabel??.hidden = true
    }
    var cell = tableView.cellForRowAtIndexPath(indexPath)
    cell?.detailTextLabel?.hidden = false

}

非常感谢,克里斯蒂安!

4

1 回答 1

1

只需使用该didSelectRowAtIndexPath方法并访问触摸的单元格。然后你可以显示detailTextLabel。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellID)  as UITableViewCell

    cell.detailTextLabel?.hidden = false
}
于 2015-02-17T23:19:14.093 回答