我有一个 UITableView 配置为“UITableViewStylePlain”,其分隔符样式为 UITableViewCellSeparatorStyleSingleLine。单元格具有背景颜色。
问题是,当您滚动表格 View 时,一旦某些单元格从屏幕上消失并返回,分隔符就不再可见。
细胞注册于:
[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
单元格代码:
- (void)customizeMyTable
{
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
NSString *cellIdentifier = [MyTableViewCell cellIdentifier];
UINib *nib = [UINib nibWithNibName:cellIdentifier bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
self.tableView.rowHeight = 50;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
[cell configure:someDataForThisRow];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor lightGrayColor];
}
有人遇到过这个问题吗?这似乎只发生在 iOS 5 上,而不发生在 iOS 6 Tableviews 上。
最佳答案
如果您在自定义单元格中实现了 layoutSubviews,并且不小心忘记了调用相应的 super 方法,您将看不到分隔线。
也许您应该检查一下是否忘记在其他方法中调用 super。
- (void)layoutSubviews
{
[super layoutSubviews]; //<-THIS LINE YOU NEED
//own code continues here
}
关于ios - UITableView 的单元格分隔符在滚动后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13166744/