Ios 分隔线问题-具有不同高度的uitableview单元格
我有一个不同单元高度的视图。我还使用以下代码添加了一个自定义分隔符行Ios 分隔线问题-具有不同高度的uitableview单元格,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我有一个不同单元高度的视图。我还使用以下代码添加了一个自定义分隔符行 UIView* separatorLineView = [[UIView alloc]initWithFrame:CGRectMake(1, cellReport.frame.size.height-1, table.frame.size.width-1, 1)]; separatorLineView.backgroundColor = [UIColor grayColor]; [cellReport.contentView
UIView* separatorLineView = [[UIView alloc]initWithFrame:CGRectMake(1, cellReport.frame.size.height-1, table.frame.size.width-1, 1)];
separatorLineView.backgroundColor = [UIColor grayColor];
[cellReport.contentView addSubview:separatorLineView];
当我滚动表格时,行与行之间会出现额外的分隔符,我不明白为什么?我错过什么了吗?帮帮我。
简而言之,UITableView在某些单元格的错误位置显示分隔符。附上一个示例图像以供参考
p.S:我没有使用自动布局
请按照以下步骤操作 并且不需要每次都查看分隔符。每次都要设置你的相框
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *myIdentifier=@"Cell";
UITableViewCell *Cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:myIdentifier];
UIView* separatorLineView;
if (Cell == nil)
{
Cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier];
separatorLineView = [[UIView alloc] initWithFrame:CGRectZero];
separatorLineView.backgroundColor = [UIColor grayColor];
separatorLineView.tag = 100;
[Cell.contentView addSubview:separatorLineView];
}
separatorLineView = (UIView *)[Cell.contentView viewWithTag:100];
separatorLineView.frame = CGRectMake(0, Cell.frame.size.height-1, Cell.frame.size.width, 1);
}
试试这个框架:CGRectMake(cell.frame.origin.x,cell.frame.size.height-1,cell.frame.size.width,1)@SaurabhPrajapati实际上我只在我的代码中使用过它。它不起作用。我已经编辑了我的答案。请看一看您是否使用自定义单元格?然后将cell.contentView addSubview:separatorLineView替换为**cellReport.contentView addSubview:separatorLineView**可能有问题谢谢。完美的解决方案。它就像一个符咒:)