Skip to content

Instantly share code, notes, and snippets.

@fabstu
Forked from johneris/IntrinsicTableView.swift
Last active August 18, 2019 17:16
Show Gist options
  • Save fabstu/2d8d78f67d24e71c9f59dbf8f5c3311d to your computer and use it in GitHub Desktop.
Save fabstu/2d8d78f67d24e71c9f59dbf8f5c3311d to your computer and use it in GitHub Desktop.
import UIKit
class IntrinsicTableView: UITableView {
override var contentSize:CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override var 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 reloadRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
super.reloadRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
super.reloadSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
override func insertRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
super.insertRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func insertSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
super.insertSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
super.deleteRows(at: indexPaths, with: animation)
self.invalidateIntrinsicContentSize()
}
override func deleteSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
super.deleteSections(sections, with: animation)
self.invalidateIntrinsicContentSize()
}
}
@fabstu
Copy link
Author

fabstu commented Jul 16, 2017

swift4

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