1
當我在UICollectionView中來回滾動時,我注意到內容在屏幕上出現和消失的單元格發生了變化。阻止UICollectionView中每個UICollectionViewCell中的內容隨着滾動而改變?
有什麼辦法可以防止這種情況發生? 我只是想適當地加載所有的內容到每個單元格,然後阻止它隨着滾動而改變。
下面是一些與此相關的代碼:
- (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;
}
感謝您的解釋:)! – justinSYDE