Ios 在swift中消失的标题

Ios 在swift中消失的标题,ios,xcode,swift,Ios,Xcode,Swift,我设法使我的细胞有了活力。我在CGFloat类型中创建了一个名为rowHeight的全局变量,并将其隐式赋值为40。我写下了这段代码: func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return rowHeight } 在触摸事件中: @IBAction func lessonCollapser(sender

我设法使我的细胞有了活力。我在CGFloat类型中创建了一个名为rowHeight的全局变量,并将其隐式赋值为40。我写下了这段代码:

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


        return rowHeight
    }
在触摸事件中:

@IBAction func lessonCollapser(sender: AnyObject) {

        if rowHeight == 40 {

        self.tableView.beginUpdates()

        UIView.animateWithDuration(1, animations: {self.rowHeight = 0})

        self.tableView.endUpdates()

        } else if rowHeight == 0 {

            self.tableView.beginUpdates()

            UIView.animateWithDuration(1, animations: {self.rowHeight = 40})

            self.tableView.endUpdates()

        }

    }
到目前为止还不错。尽管它正在制作动画,但仍存在一些问题

首先:我的自定义标题消失

Second:我得到一个错误:“没有重用表单元格的索引路径”。我认为,因为没有索引路径,所以标题消失了。这是意料之中的。不可预料的是,为什么在使用动画时我的表的索引路径消失了?我认为这是因为
beginUpdates()
endUpdates()
。有人能给我一些建议吗

“我的标题”视图的代码:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {



        let headerCell = tableView.dequeueReusableCellWithIdentifier("HeaderCell") as! lessonHeaderTableViewCell

        switch (section) {

        default:
            headerCell.lessonHeader.setTitle("TEST HEADER", forState: .Normal)

        }


        return headerCell
    }
上面的代码是这样的:我创建了一个带有“headerCell”标识符的原型单元。我在里面扔了一颗纽扣。我创建了一个名为“lessonHeaderTableViewCell”的swift文件。我将其指定为原型单元的类,以便它可以控制它。最后,我为按钮创建了一个名为“lessonHeader”的出口,位于我创建的swift文件内