【发布时间】:2012-10-31 20:13:47
【问题描述】:
我有一个 UITableView 配置为“UITableViewStylePlain”,其分隔符样式为 UITableViewCellSeparatorStyleSingleLine。单元格具有背景颜色。
问题是,当您滚动表格视图时,一旦某些单元格从屏幕上消失并被带回来,分隔符就不再可见。
单元格注册到:
[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。
【问题讨论】:
-
显示 tableview 的代表。 -(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
-
确保 tableView 的 rowHeight 是您的单元格的确切高度,或者您的单元格高度与 rowHeight 函数(在您的委托中)返回的高度完全匹配。
-
即使我也面临同样的问题。您找到解决方案了吗?这里没有一个解决方案对我有用。我在所有版本的 iOS 中都面临这个问题,直到 11.x
-
我实际上遇到了一个特殊的情况。当数据库返回空数组时,分隔符被删除。因此,即使在数据库不为零时重新添加分隔符后,分隔符也会丢失或出现两个分隔符。但我发现这是因为我使用的自定义单元格有一个背景颜色为灰色的容器视图。所以我修改它有白色。请检查您的自定义单元格的内容及其属性。
标签: ios uitableview