CollectionViewCell i子類包含一個UILabel。 爲了得到網格,我添加了一個CGRectInset到單元格的UILabel。UICollectionViewCells子視圖滾動後呈現錯誤
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor orangeColor];
self.label = [[UILabel alloc] initWithFrame:CGRectInset(self.bounds, 1.0, 1.0)];
self.label.numberOfLines = 0;
self.label.layer.shouldRasterize = true;
[self addSubview:self.label];
}
return self;
}
按照要求
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"indexPathSection: %i in row: %i", indexPath.section, indexPath.row);
MyCVCell *cell = (MyCVCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSString *str = [NSString stringWithFormat:@"%@", [[self.cData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
cell.label.text = str;
return cell;
}
所有看起來很好,直到我滾動。任何想法可能是什麼原因?
滾動 向下滾動 之前向上滾動
請從'cellForItemAtIndexPath'發佈您的代碼。 –
@ 0x7fffffff將其添加到問題 – peko
嘗試添加您的子視圖到單元格contentView而不是直接到單元格? – wattson12