EXC_BAD_ACCESS in heightForRowAtIndexPath iOS

后端 未结 5 1382
眼角桃花
眼角桃花 2020-11-28 14:27

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

5条回答
  •  情书的邮戳
    2020-11-28 14:56

    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!
                 }
    
    }
    

提交回复
热议问题