Created
April 29, 2020 18:14
-
-
Save sseno/d0a462c600259272fa6bb96c2a76e619 to your computer and use it in GitHub Desktop.
Swift 5
This file contains hidden or 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
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