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];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值