Wrong UITableViewCell height with UITableViewAutomaticDimension

前端 未结 4 1679
盖世英雄少女心
盖世英雄少女心 2021-02-09 08:05

I make custom cell with 2 multiline labels and pin this labels to all sides. When in -tableView:heightForRowAtIndexPath: for iOS >= 8 I return

相关标签:
4条回答
  • 2021-02-09 08:43

    The problem is gone when I don't set tableView's estimatedRowHeight for iOS 8 and update preferredMaxLayoutWidth every time when sets the text for multiline labels

    0 讨论(0)
  • 2021-02-09 08:46

    I solved this issue by setting "text" property of multiline labels to "nil":

    override func prepareForReuse() {
        _label.text = nil
    }
    

    Also table properies "estimatedRowHeight" and "rowHeight" should be set correctly:

    _tableView.estimatedRowHeight = 44
    _tableView.rowHeight = UITableViewAutomaticDimension
    
    0 讨论(0)
  • 2021-02-09 08:50

    Set automatic dimension in viewDidLoad() method or viewWillAppear() (both code in same place)

        tableView.rowHeight = UITableViewAutomaticDimension;
        tableView.estimatedRowHeight = 160.0;//(Maximum Height that should be assigned to your cell)
    

    Visit Using Auto Layout in UITableView for dynamic cell layouts & variable row heights an intuitive guide for both iOS 7 and iOS 8

    0 讨论(0)
  • 2021-02-09 09:03

    Automatic dimension is not working well for some UILabel if that label is aligned with different label by top edges or bottom edges. Just make sure that you do not have such alignments.

    0 讨论(0)
提交回复
热议问题