gpt4 book ai didi

ios - 分隔线问题 - 具有不同高度的 uitableview 单元格

转载 作者:行者123 更新时间:2023-11-29 10:28:20 24 4
gpt4 key购买 nike

我有一个具有不同单元格高度的 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 addSubview:separatorLineView];

当我滚动表格时,行之间会出现额外的分隔符,我不明白为什么?我错过了什么吗?帮帮我。简而言之,UITableView 在某些单元格的错误位置显示分隔符。已附上示例图像以供引用。

附言:我没有使用自动布局

enter image description here

最佳答案

请按照以下步骤操作

并且不需要每次都查看分隔符。每次都设置你的框架。

-(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);

}

关于ios - 分隔线问题 - 具有不同高度的 uitableview 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31019465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com