
I managed to set up animated cells. I created a global variable called rowHeight in type CGFloat and implicitly assigned it as 40. I wrote this code:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return rowHeight
}
In touch event:
@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()
}
}
So far so good. Despite the fact that he is animating, there are several problems.
First: My custom headers disappear.
Second: I get the error: "There is no pointer path to use the table cell." I think because there are no index paths, the headings are gone. It is expected. What is not expected is why my table index paths disappeared when I used the animation? I think this is due to beginUpdates()and endUpdates(). Can someone advise me to do something?
Code for my header:
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". , . , "lessonHeader", .
