UITableViewAutomaticDimension在Xcode 6.3中不起作用

Ste*_*tic 17 xcode uitableview nslayoutconstraint xcode6.3

我将我的Xcode与Swift 1.2一起更新为6.3,然后我进行了转换.

除了表视图的动态行高以外,一切正常.我有3个完全不同的表视图,所以它可能不是影响bug的其他东西.

我将所有表视图设置为:

tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)

并且我的所有xib文件都受到了适当的约束.

有任何想法吗?

Ken*_*Ken 54

我只是简单地将UITableViewAutomaticDimension添加到estimaterowforindexpath.您可以在BEAM应用程序(在"人员"类别下)查看它的工作原理.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
Run Code Online (Sandbox Code Playgroud)

  • 是的,你应该提供一个估计.另外,根据[docs](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath :) ,使用回调而不是`rowHeight`和`estimatedRowHeight`属性有性能影响.您可以将`rowHeight`设置为`UITableViewAutomaticDimension`,然后将`estimatedRowHeight`设置为任意估计值. (4认同)