Skip to content

Instantly share code, notes, and snippets.

@MarcelWeidum
Created April 11, 2017 10:37
Show Gist options
  • Save MarcelWeidum/d6100d0133050c07d7b9e2b4028e4e95 to your computer and use it in GitHub Desktop.
Save MarcelWeidum/d6100d0133050c07d7b9e2b4028e4e95 to your computer and use it in GitHub Desktop.
Expanding cell
import UIKit
class NewSongExpandableTableViewCell: UITableViewCell {
@IBOutlet var firstView: UIView!
@IBOutlet var secondView: UIView!
@IBOutlet var heightConstraintSecondView: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
var showSong = false {
didSet {
heightConstraintSecondView.priority = showSong ? 250 : 999
}
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if selectedIndex == indexPath.row {
return 210
} else {
return 84
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if selectedIndex == indexPath.row {
selectedIndex = -1
} else {
selectedIndex = indexPath.row
}
self.tableView.beginUpdates()
self.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
self.tableView.endUpdates()
}
@eddie1707
Copy link

MIJN CODE IS BETER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment