对于某些单元格,UITableView在iOS8中的错误位置显示分隔符 [英] UITableView displays separator at wrong position in iOS8 for some cells
问题描述
我们有一个UITableView,它适用于iOS7但是当我在iOS8模拟器中尝试时,我看到大多数单元格的单元格分隔符放置不正确。奇怪的是,一些单元格正确显示了分隔符。
We have a UITableView and it was working fine for iOS7 but when I tried in the iOS8 simulator, I saw the cell separator was placed incorrectly for most cells. Strangely, some cells display the separator correctly.
参见附图:
我设置单元格高度为方式:
I set the cell height this way:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70.0f;
}
你知道发生了什么吗?谢谢!
Do you know what's happening? Thanks!
编辑:
我在此期间使用的解决方法是禁用分隔符.. 。
A workaround I'm using in the meantime is to disable the separator...
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
...并在单元格视图中自己绘制...
...and paint it myself in the cell view...
UIView* separator = [[UIView alloc] initWithFrame:CGRectMake(20, cellHeight-1, frame.size.width - 40, 1)];
separator.layer.borderWidth = 1;
separator.layer.borderColor = [[UIColor grayColor] CGColor];
[self addSubview:separator];
...但我不想这样做。
...but I'd like not to do it.
推荐答案
我遇到了同样的问题,这就是我如何解决它的问题:
I had the same problem and here is how I solved it:
如果您使用的是您的表格视图的自定义单元格已经覆盖了layoutSubviews,您需要在方法开头调用它的superview方法:
If you are using a custom cell for your table view and you have overridden layoutSubviews, you need to call it's superview's method at the beginning of the method:
- (void)layoutSubviews
{
[super layoutSubviews];
// Your implementation
}
这篇关于对于某些单元格,UITableView在iOS8中的错误位置显示分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!