mdmb
mdmb

Reputation: 5283

UITableViewCell changing height

I want to change height of the touched row in table view (so it expands):

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTableViewCell
    if let currentSelection = self.currentSelection {
        if currentSelection == indexPath {
            tableView.deselectRowAtIndexPath(indexPath, animated: true)
            self.currentSelection = nil
            tableView.beginUpdates()
            tableView.endUpdates()
            setupAnimation(cell, hide: true) //Custom animation inside the cell
        }
    } else {
        self.currentSelection = indexPath
        tableView.beginUpdates()
        tableView.endUpdates()
        setupAnimation(cell, hide: false) //Custom animation inside the cell
    }
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if let currentSelection = self.currentSelection {
        if indexPath == currentSelection {
            return 80.0
        }
    }
    return 50.0
}

This is working - the height changes to 80.0 when I tap the row, and comes back to 50.0 when I tap it again. The thing is that my separator is not moving.

Not only it is not moving, but when I tap the cell:

  1. the height expands ->
  2. the tapped cell separator stays in the same place ->
  3. the separator of the cell above disappears

What am I doing wrong or what am I missing here?

EDIT

I have tried to override layoutSubviews method and forgot about that - I didn't call super.layoutSubviews() in it. Now the separator of selected cell is moving down with it but I still have problem with the separator of the cell above disappearing

Upvotes: 0

Views: 129

Answers (2)

mdmb
mdmb

Reputation: 5283

If you don't have to have your cell selected this thread should be the answer:

UITableView separator line disappears when selecting cells in iOS7

Upvotes: 0

Sunil Sharma
Sunil Sharma

Reputation: 2689

try to reload that cell

tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) //try other animations
tableView.endUpdates()

Upvotes: 2

Related Questions