0

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

mdmb
  • 4,833
  • 7
  • 42
  • 90

2 Answers2

2

try to reload that cell

tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) //try other animations
tableView.endUpdates()
Sunil Sharma
  • 2,653
  • 1
  • 25
  • 36
  • In CustomTableViewCell class in method `awakeFromNib` try `self.clipsToBounds = true` – Sunil Sharma Mar 15 '16 at 20:32
  • I'm so stupid. I tried to override layout subviews but didn't call super in that method. Now the separator of selected cell is moving down, but I still have problem with separator of the above cell disappearing – mdmb Mar 15 '16 at 20:37
  • Did try it, it didn't have effect on the separator not moving down, and neither has it on the existing problem – mdmb Mar 15 '16 at 20:41
  • can u share screenshot ? that will be more helpful to understand the problem. – Sunil Sharma Mar 15 '16 at 20:45
  • check this thread http://stackoverflow.com/questions/18924589/uitableviewcell-separator-disappearing-in-ios7 – Sunil Sharma Mar 15 '16 at 21:06
  • The solutions don't work for me. I don't know - maybe it does something to do with that I set up cell.selectionStyle = UITableViewCellSelectionStyle.None in cellForRowAtIndexPath? – mdmb Mar 15 '16 at 21:18
  • may be just try commenting that line. are u checking this on simulator or device. if simulator then check on 100% scale – Sunil Sharma Mar 15 '16 at 21:29
0

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

Community
  • 1
  • 1
mdmb
  • 4,833
  • 7
  • 42
  • 90