问题
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