Skip to content

Instantly share code, notes, and snippets.

@sseno
Created April 29, 2020 18:14
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 sseno/d0a462c600259272fa6bb96c2a76e619 to your computer and use it in GitHub Desktop.
Save sseno/d0a462c600259272fa6bb96c2a76e619 to your computer and use it in GitHub Desktop.
Swift 5
class IntrinsicTableView: UITableView {
override var contentSize:CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
self.layoutIfNeeded()
return CGSize(width: UIView.noIntrinsicMetric, height: self.contentSize.height)
}
override func endUpdates() {
super.endUpdates()
self.invalidateIntrinsicContentSize()
}
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
}
override func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.reloadRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func reloadSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.reloadSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
override func insertRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.insertRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func insertSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.insertSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.deleteRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.deleteSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment