仅展开已点击的单元格 [英] Expand only the cell that has been tapped

查看:58
本文介绍了仅展开已点击的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一些代码,可以在点击某个单元格时对其进行扩展.问题是我还没有想出如何仅扩展已点击的单元格.目前,我的代码只是扩展了所有单元格.

I have some code in my app that expands a cell when it is tapped. The problem is that I haven't figured out how to only expand the cell that has been tapped. At the moment my code just expands all of the cells.

这是我的代码:

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
}

我只需要扩展已点击的单元格该怎么做?

What do I need to do to only expand the cell that has been tapped?

推荐答案

以下内容对我有用.单元格高70,并在点击时扩展:

The following worked for me. The cells are 70 high and expand when tapped :

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

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

Then I slightly modified the following two methods:

 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
}

这篇关于仅展开已点击的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆