【发布时间】:2014-10-30 13:00:14
【问题描述】:
我正在尝试计算使用自动布局进行布局的表格视图单元格的高度。由于这也必须与 iOS7 兼容,因此我需要为 heightForRowAtIndexPath: 返回一个有效高度。
我正在做的事情如下:
if (self.userRatingsAbbreviatedTextCell == nil) {
self.userRatingsAbbreviatedTextCell = [[UserRatingsAbbreviatedTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
[self.userRatingsAbbreviatedTextCell prepareForReuse];
UserRating *rating = [self.paginationModel ratingAtIndex:reviewIndex];
[self.userRatingsAbbreviatedTextCell configureCellForHotelUserRating:rating];
[self.userRatingsAbbreviatedTextCell layoutIfNeeded];
CGSize size = [self.userRatingsAbbreviatedTextCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height;
该单元格有一个披露指示符。当我询问单元格的contentView 宽度时,它是296。然而在cellForRowAtIndexPath: 中,在出列单元格后,其contentView 宽度为289,这是用于渲染的大小。有没有人遇到过这样的问题?我需要做什么才能让单元格正确设置其contentView 宽度?
【问题讨论】:
-
如果表格是静态的,您可以从
super获取高度 -
但它仍然损坏......我对此进行了更多调查,发现在表格视图上调用
_configureCellForDisplay:forIndexPath:并将其传递给单元格会将内容视图的大小调整为正确的大小,但是因为这是私有 API,所以不能解决问题... -
是的,这是我们进行单元格布局的方式,但是一旦有显示指示器或类似的附件视图,iOS7 兼容方式就不再适用于 iOS8。
-
我没有得到你的答案,究竟是什么坏了,视图调试的结果是什么?
标签: ios objective-c uitableview ios7