Can you animate a height change on a UITableViewCell when selected?

前端 未结 21 1241
天涯浪人
天涯浪人 2020-11-22 04:41

I\'m using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular pers

21条回答
  •  野性不改
    2020-11-22 04:50

    Heres a shorter version of Simons answer for Swift 3. Also allows for toggling of the cell's selection

    var cellIsSelected: IndexPath?
    
    
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        cellIsSelected = cellIsSelected == indexPath ? nil : indexPath
        tableView.beginUpdates()
        tableView.endUpdates()
      }
    
    
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if cellIsSelected == indexPath {
          return 250
        }
        return 65
      }
    

提交回复
热议问题