改变 UITableViewCell 的高度

Change UITableViewCell height touch up inside

正如标题所说,我想让我的单元格动态改变高度。我尽量说清楚。当我在一个单元格(原型单元格)内向上触摸时,单元格改变高度(从 44 到 88);在单元格中有一个 UIImage(88px 高度)部分隐藏并且单元格隐藏的地方有视图,向上触摸开始转到第二个 tableView;当我在另一个单元格内触摸前一个单元格 return 到 44px 高度时,另一个单元格将高度更改为前一个。遵循我需要做的计划。

我觉得这很难,所以如果有人能帮我做这个功能,我将不胜感激!!或者,如果您知道任何可以获取想法的示例(例如 gitHub),请报告我! 非常感谢:-)

还不错。我已经这样做了,可能有更聪明的方法来做到这一点。 重要的是 tableView.beginUpdate 和 ....endUpdate.

  //
    //  DynamicTableViewController.swift
    //  DynamicCellTest
    //
    //  Created by Lars Christoffersen on 27/08/15.
    //  Copyright (c) 2015 Lars Christoffersen. All rights reserved.
    //

    import UIKit

    class DynamicTableViewController: UITableViewController {

        var dataCource = ["A","B","C","D","E","F","G","H"]
        var extraHeight:CGFloat?
        var selectedRowIndex:Int?

        override func viewDidLoad() {
            super.viewDidLoad()
        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }

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


            if extraHeight != nil && selectedRowIndex != nil && selectedRowIndex == indexPath.row{
                return 41 + extraHeight!
            }else{
                return 41
            }
        }


        override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            self.tableView.beginUpdates()
            selectedRowIndex = indexPath.row
            extraHeight = 100
            self.tableView.endUpdates()

        }

        override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
            self.tableView.beginUpdates()
            selectedRowIndex = indexPath.row
            extraHeight = 0
            self.tableView.endUpdates()
        }

        override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return 1
        }

        override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return dataCource.count
        }


        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell

            cell.textLabel?.text = dataCource[indexPath.row]
            return cell
        }
    }