UITableViewAutomaticDimension return -1

2019-09-15 12:03发布

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.

标签: ios swift ios8
1条回答
爷的心禁止访问
2楼-- · 2019-09-15 12:55

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:
查看更多
登录 后发表回答