ios - UITableView 的单元格分隔符在滚动后消失

标签 ios uitableview

我有一个 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/

相关文章:

ios - 是否可以使背景 ViewController 不可点击?

ios - UICollectionView Scroll 无法正确分页

ios - 为什么嵌入 UINavigationController 中的 UIVewController 的第一个 subview 的位置会改变?

ios - UITableView 调用 cellFor row 但不在 UI 中绘制

ios - Swift:如何在不添加 segue 的情况下切换回以前的 UITableViewController

ios - 为什么我的语言包路径在iOS Swift中返回nil?

ios - tableView.dequeueReusableCellWithIdentifier() 导致应用挂起

ios - 以编程方式调整 Storyboard 中 UITableView 的 y 值

ios - scrollToRowAtIndexPath :atScrollPosition causing table view to "jump"

ios - 强制 iOS 设备改变方向