Labels are lingering in my reusable table cells

后端 未结 3 872
半阙折子戏
半阙折子戏 2021-01-24 21:04

I have a table whose cells contain labels. Whenever I dequeue a reusable cell, the old labels are still lingering on it. I was able to remove them with this:

            


        
3条回答
  •  自闭症患者
    2021-01-24 21:46

    I kinda did what Yuji suggested. Instead of putting in new labels on each iteration, I checked whether the cell contained labels and then either edited the labels if they were there or put them in if they weren't. Code goes like this:

        if([[newcell.contentView subviews] count]>=2 && [[[[newcell.contentView subviews] objectAtIndex:0]class] isSubclassOfClass:[UILabel class]] && 
       [[[[newcell.contentView subviews] objectAtIndex:1]class] isSubclassOfClass:[UILabel class]])
    {
        //change the text of the labels
    }
    else
    {
        //add the labels to the cell
    }
    

提交回复
热议问题