【发布时间】:2015-07-13 00:44:07
【问题描述】:
当我在 UICollectionView 中来回滚动时,我注意到屏幕上出现和消失的单元格中的内容发生了变化。
有什么方法可以防止这种情况发生吗? 我只想将所有内容适当地加载到每个单元格中,然后在滚动时防止它发生变化。
下面是一些与此相关的代码:
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
UILabel *label = (UILabel *)[cell viewWithTag:100];
if (!label) {
label = [[UILabel alloc] initWithFrame:cell.bounds];
label.tag = 100;
label.text = [self.array objectAtIndex:indexPath.row];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
[cell.contentView addSubview:label];
}
return cell;
}
【问题讨论】:
标签: ios objective-c scroll uicollectionview uicollectionviewcell