当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS collectionViewCell防止复用的两种方法

IOS collectionViewCell防止复用的两种方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

ios collectionviewcell防止复用的两种方法

collectionview 防止cell复用的方法一:

//在创建collectionview的时候注册cell(一个分区)

uicollectionviewcell *cell=[collectionview dequeuereusablecellwithreuseidentifier:@“cell" forindexpath:indexpath];

  for (uiview *view in cell.contentview.subviews) {

    [view removefromsuperview];

  }



collectionview 防止cell复用的方法二:

//在cellforitem方法中注册cell(多个分区)

 nsstring *identifier=[nsstring stringwithformat:@"%ld%ld",(long)indexpath.section,(long)indexpath.row];

  

  [collect registerclass:[uicollectionviewcell class] forcellwithreuseidentifier:identifier];

  

  uicollectionviewcell *cell=[collectionview dequeuereusablecellwithreuseidentifier:identifier forindexpath:indexpath];

  

  for(id subview in cell.contentview.subviews){

    

    if(subview){

      

      [subview removefromsuperview];

    }

    

  }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网