Skip to content

Instantly share code, notes, and snippets.

@johneris
Last active March 10, 2022 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johneris/2263781090f271a7a647 to your computer and use it in GitHub Desktop.
Save johneris/2263781090f271a7a647 to your computer and use it in GitHub Desktop.
import UIKit
class IntrinsicTableView: UITableView {
override var contentSize:CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override func intrinsicContentSize() -> CGSize {
self.layoutIfNeeded()
return CGSize(width: UIViewNoIntrinsicMetric, height: self.contentSize.height)
}
override func endUpdates() {
super.endUpdates()
self.invalidateIntrinsicContentSize()
}
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
}
override func reloadRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) {
super.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
override func reloadSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) {
super.reloadSections(sections, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
override func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) {
super.insertRowsAtIndexPaths(indexPaths, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
override func insertSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) {
super.insertSections(sections, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) {
super.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) {
super.deleteSections(sections, withRowAnimation: animation)
self.invalidateIntrinsicContentSize()
}
}
@fabstu
Copy link

fabstu commented Jul 16, 2017

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