iOS 8单元格调整大小 [英] iOS 8 cell resizing
问题描述
我有一个 UITableViewCell
的子类,我覆盖 setFrame:
以向单元格添加插入内容。在iOS 7中,一切似乎都运行良好,另一方面,在iOS 8上,表视图正确加载单元格但是当我刷新tableview时,单元格会调整大小。
通过注释 setFrame
中的代码,tableview行为正确,但我也松开了插件。
有没有人经历过这个?
I have a subclass of a UITableViewCell
and I override setFrame:
to add insets to cell. In iOS 7 everything seems to work fine, on iOS 8 on the other hand, the table view loads the cells correctly but when I refresh the tableview the cells are resized.
By commenting the code in the setFrame
the tableview behaves correctly, but I also loose the insets.
Has anyone experienced this?
更新:AFAIK,在iOS 8中,单元格框架高度与行高匹配。
UPDATE: AFAIK, in iOS 8 the cell frame height matches the row height.
推荐答案
我遇到了类似的问题。
通过以下方式解决:
- (void)setFrame:(CGRect)frame
{
NSInteger inset = kDefaultViewPadding;
frame.origin.x += inset;
frame.size.width = kMainScreenWidth - 2*inset;
[super setFrame:frame];
}
其中
#define kMainScreenWidth ([[UIScreen mainScreen] bounds].size.width)
,
不要使用以下代码:
frame.origin.x += TABLE_PADDING;
或
frame.size.width = self.superview.frame.size.width - (2.0f * TABLE_PADDING);
否则,每次刷新tableview时,单元格的宽度减小(2.0f * TABLE_PADDING)。
otherwise, every time refresh tableview , the cell's width reduce (2.0f * TABLE_PADDING).
这篇关于iOS 8单元格调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!