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

后端 未结 3 1165
温柔的废话
温柔的废话 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:26

    As Romit Mewada suggested you can use that but each time you have alloc & add new UIImageView.

    Instead of that you can send nil to the image of that UIImageView.

    Implement in this way.

    if (cell == nil)
    {
        //get your cell or alloc & initialize
        // create and add imageView
    }
    
    UIImageView* imageView = [cell.contentView viewWithTag:indexPath.row];
    imageView.image = nil;
    //do your other task, you can use the same imageView to add other image for other row.
    

提交回复
热议问题