I\'m working on an application where I have a custom subclass of UITableViewCell. I want to make the cell\'s height dynamic based on the text inside it. I try do do that in
SWIFT:
Use this to know when the tables have loaded:
extension UITableView {
func reloadData(completion: ()->()) {
UIView.animateWithDuration(0, animations: { self.reloadData() })
{ _ in completion() }
}
}
Create a boolean value
var tables_loaded = Bool(false)
Then in viewDidLoad:
tableView.reloadData {
tables_loaded = true
// call functions or other stuff regarding table manipulation.
// tableView.beginUpdates()
// tableView.endUpdates()
}
then in
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if tables_loaded {
let cell = tableView.cellForRowAtIndexPath(indexPath)
// Do your magic here!
}
}