Duplicating subviews(UIButton and UIImageView) of UITableViewCell contentView on scrolling

后端 未结 3 1163
温柔的废话
温柔的废话 2020-12-07 03:57

In my tableView, in some cells i have added an imageView as subview of cell contentView. On scrolling tableView up and down these images duplicating on other cells also. But

3条回答
  •  失恋的感觉
    2020-12-07 04:20

    The problem is solved now. I have used the following line inside the else case of creating new tableViewCell.

    [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

    I have edited my code as shown below :

    if (cell == nil) 
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        }
        else
        {
            [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        }
    

提交回复
热议问题