解决问题之前,在cell上添加了label,但是给label添加label.text之后滑动时即用到cell重用时label的内容总是重叠,从网上搜了好多,现在终于解决了,总结一下我用的方法:就是给重用的cell也设置不同的标示符。首先,对于tableviewcell
只需要在定义标示符的时候换成这句就可以了
这样就能保证每一行的标示符都不一样,也就不会出现重用问题。
还有在collectionViewcell时用同样的方法解决
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];