仅展开已轻触的单元格

时间:2014-10-11 19:04:39

标签: ios uitableview swift

我的应用中有一些代码可以在点击时扩展单元格。问题是我还没弄明白如何只扩展已被挖掘的单元格。目前我的代码只是扩展了所有单元格。

这是我的代码:

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

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == selectedRowIndex.row {
        if cellTapped == false {
            cellTapped = true
            return 141
        } else {
            cellTapped = false
            return 70
        }
    }
    return 70
}

如果只展开已点击的单元格,我需要做什么?

1 个答案:

答案 0 :(得分:16)

以下对我有用。电池高70英寸,并在敲击时扩展:

class ViewController: UITableViewController {
    var cellTapped:Bool = true
    var currentRow = 0;

然后我稍微修改了以下两种方法:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var selectedRowIndex = indexPath
    currentRow = selectedRowIndex.row

    tableView.beginUpdates()
    tableView.endUpdates()
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == currentRow {
        if cellTapped == false {
            cellTapped = true
            return 141
        } else {
            cellTapped = false
            return 70
        }
    }
    return 70
}
相关问题