How to change cell height dynamically in UITableView static cell

前端 未结 4 649
盖世英雄少女心
盖世英雄少女心 2021-01-12 07:42

I am using UITableViewController instead detailView to show one entity details. I populated one row of data from PFQuery in my viewDidLoad method.

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-12 08:15

    If it is IOS 8 OR 9, there is a simple fix.

    1. Set up the constrains for the UILabel. (top, left, bottom, right)
    2. Set lines of the UILabel to 0
    3. Add the following code in the viewDidLoad method of the ViewController:
    tableView.estimatedRowHeight = 68.0
    tableView.rowHeight = UITableViewAutomaticDimension
    
    1. override the function:
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

提交回复
热议问题