Created
April 11, 2017 10:37
-
-
Save MarcelWeidum/d6100d0133050c07d7b9e2b4028e4e95 to your computer and use it in GitHub Desktop.
Expanding cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MIJN CODE IS BETER