Is it possible to obtain a dynamic table view section header height using Auto Layout?

后端 未结 8 821
清歌不尽
清歌不尽 2020-11-28 02:36

New in iOS 8, you can obtain 100% dynamic table view cells by simply setting the estimated row height, then layout your elements in the cell using Auto Layout. If the conten

8条回答
  •  没有蜡笔的小新
    2020-11-28 03:24

    I modified iuriimoz answer. Just replaced viewWillAppear method:

    tableView.sectionHeaderHeight = UITableViewAutomaticDimension
    tableView.estimatedSectionHeaderHeight = 25
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        // Recalculates height
        tableView.layoutIfNeeded() 
    }
    

    Also add the tableView.layoutIfNeeded() to

    override func viewDidAppear(_ animated: Bool) {
    
        super.viewDidAppear(animated)
        tableView.layoutIfNeeded()
    }
    

    For iOS 10

    tableView.beginUpdates()
    tableView.endUpdates()
    

    have "fade" animation effect on viewWillAppear for me

提交回复
热议问题