ios - 选中单元格时如何更改单元格的高度?

标签 ios swift tableview

我四处寻找其他答案,但似乎没有任何效果。我已经实现了这段代码:

var selectedCellIndexPath: NSIndexPath?
let selectedCellHeight: CGFloat = 88.0
let unselectedCellHeight: CGFloat = 51.0

// Override to support editing of individual itemCells

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    if selectedCellHeight == indexPath {
        return selectedCellHeight
    }
    return unselectedCellHeight
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if selectedCellIndexPath != nil && selectedCellIndexPath == indexPath {
        self.selectedCellIndexPath = nil
    } else {
        self.selectedCellIndexPath = indexPath
    }

    tableView.beginUpdates()
    tableView.endUpdates()

    if selectedCellIndexPath != nil {
        // THis ensure, that the cell is full visile once expended 
        tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .None, animated: true)
    }
}

我从其他 StackOverFlow 答案中得到它,但是当我运行我的应用程序时,单元格仅显示它已被选中(通过着色),然后不执行任何其他操作。任何帮助都会很棒!我是初学者!

最佳答案

if selectedCellHeight == indexPath {

应该是

if selectedCellIndexPath == indexPath {

关于ios - 选中单元格时如何更改单元格的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36226368/

相关文章:

ios - 将 FFmpeg 编译为 iOS 8 框架

ios - 原生 Facebook Audience Network 广告不可点击

php - 当从表中添加/删除列时,如何更新 mysql View ?

JavaFX:如何在向 TableView 添加列时显示动画 ProgressIndicator?

swift - 当从一个 View Controller 转到另一个 View Controller (例如 Swift 中的 Instagram 或 Facebook)时,如何在 TableView 中保留当前的 ​​IndexPath.row?

ios - 我如何重新填充 TableView Controller ?

ios - 如何在 UInt8 数组中存储负数

ios - AVAudioSession.sharedInstance 没有被调用

swift - 我想从安装了 cocoapods 的 Xcode 项目中删除 firebase

ios - UIImagePickerController 不压缩视频