Objective c 当滚动UITableView时,它与iOS名称重叠

Objective c 当滚动UITableView时,它与iOS名称重叠,objective-c,ios7,uicollectionview,alassetslibrary,alasset,Objective C,Ios7,Uicollectionview,Alassetslibrary,Alasset,当我滚动时,tableview提供了这种类型的重叠 我在CellForRow AtIndexPath方法中编写以下代码,我以编程方式创建tableview -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"cell"; UITableViewCell *cell = [t

当我滚动时,tableview提供了这种类型的重叠

我在CellForRow AtIndexPath方法中编写以下代码,我以编程方式创建tableview

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

NSDictionary *info = [ASSETHELPER getGroupInfo:_groupArray[indexPath.row]];
UIImageView *view;

if (indexPath.row % 2) {
    view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dark_bg"]];
}else{
    view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"light_bg"]];
}
cell.backgroundView=view;

UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
imgView.backgroundColor=[UIColor clearColor];
[imgView.layer setCornerRadius:25];
[imgView.layer setMasksToBounds:YES];
[imgView.layer setBorderColor:[UIColor whiteColor].CGColor];
[imgView setImage:[info objectForKey:@"thumbnail"]];
[cell.contentView addSubview:imgView];

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(80, 20, 200, 30)];

[label setText:[info objectForKey:@"name"]];
[cell.contentView addSubview:label];

return cell;

}

请尝试此代码。您已使用dequeueReusableCellWithIdentifier:

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell %d",indexPath.row];

UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:indexPath];

if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

我们不是巫师或通灵者。添加一些代码和更多详细信息。您尚未正确处理单元格的可重用性。在这里发布你的CellPathForRowatineXpath代码。好多了。对不起,如果我以前听起来很粗鲁。这里的问题是
[cell.contentView addSubview:label]。每次调用
cellforrowatinexpath:
时,您每次都在添加一个新标签。由于单元格被重复使用,以前添加的标签将永远不会删除。请检查并告知您。检查我的个人资料,您将获得我的邮件id。请帮助我将视频保存到自定义相册中。创建单元格后只需添加此代码。我想这会对你有帮助。for(UIImageView*v在[cell.contentView子视图]中){[v removeFromSuperview];NSLog(@“%@hello\n\n\n%@”,v[cell.contentView子视图];}for(UILabel*v在[cell.contentView子视图]中){[v removeFromSuperview];NSLog(@“%@hello\n\n\n\n\n%@”,v,[cell.contentView子视图];}您知道正确设置代码格式不是一门科学。你们给出的每一个答案我都做了,但现在我要投反对票。一旦您正确设置了答案的格式,使其可读,我将删除-1
You can try with it. Just remove the previous contentView after create a table cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell==nil)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    //****add this code*******//
    for (UIImageView *v in [cell.contentView subviews])
    {
        [v removeFromSuperview];
        NSLog(@"%@ hello \n\n\n\n\n%@",v,[cell.contentView  subviews]);
    }
    for (UILabel *v in [cell.contentView subviews])
    {
        [v removeFromSuperview];
        NSLog(@"%@ hello \n\n\n\n\n%@",v,[cell.contentView  subviews]);
    }/////////
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *info = [ASSETHELPER getGroupInfo:_groupArray[indexPath.row]];
    UIImageView *view;
    if (indexPath.row % 2)
    {
        view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dark_bg"]];
    }
    else
    {
        view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"light_bg"]];
    }
    cell.backgroundView=view;
    UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
    imgView.backgroundColor=[UIColor clearColor];
    [imgView.layer setCornerRadius:25];
    [imgView.layer setMasksToBounds:YES];
    [imgView.layer setBorderColor:[UIColor whiteColor].CGColor];
    [imgView setImage:[info objectForKey:@"thumbnail"]];
    [cell.contentView addSubview:imgView];

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(80, 20, 200, 30)];

    [label setText:[info objectForKey:@"name"]];
    [cell.contentView addSubview:label];

    return cell;
}