UITableViewAutomaticDimension return -1

2019-09-15 12:50发布

问题:

Hi I make tableviewcontroller class and I want to get cell height dynamicly so i use UITableViewAutomaticDimension but it always return me -1.

    tableView.rowHeight = UITableViewAutomaticDimension
    println("\(tableView.rowHeight)")
    tableView.estimatedRowHeight = 44

when I do tableView.rowHeight = 44 everything works great. My superclass is UIViewController.

回答1:

You can only use UITableViewAutomaticDimension for footer/header height and only if you implement:

- tableView:titleForHeaderInSection:

If you're implementing the:

- tableView:viewForHeaderInSection:

it will not work. UITableViewAutomaticDimension is not intended to be used to set the row height. Use rowHeight and specify your value or implement:

- tableView:heightForRowAtIndexPath:


标签: ios swift ios8