`
xiaotongeye
  • 浏览: 18379 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

cell重用问题

阅读更多
解决问题之前,在cell上添加了label,但是给label添加label.text之后滑动时即用到cell重用时label的内容总是重叠,从网上搜了好多,现在终于解决了,总结一下我用的方法:就是给重用的cell也设置不同的标示符。首先,对于tableviewcell
    static NSString *CellIdentifier =@"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

只需要在定义标示符的时候换成这句就可以了
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];

这样就能保证每一行的标示符都不一样,也就不会出现重用问题。
还有在collectionViewcell时用同样的方法解决
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
    [m_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics