UITableViewAutomaticDimension return -1

Deadly 提交于 2019-12-12 01:57:40

问题


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:


来源:https://stackoverflow.com/questions/24844173/uitableviewautomaticdimension-return-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!