【发布时间】:2012-12-20 13:41:50
【问题描述】:
我子类化的 CollectionViewCell 只包含一个 UILabel。 为了获得网格,我将带有 CGRectInset 的 UILabel 添加到单元格中。
- (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 将其添加到问题中
-
尝试将您的子视图添加到单元格 contentView 而不是直接添加到单元格中?
-
@wattson12 试过了,没有任何改变
-
你有没有解决过这个问题,或者至少想出了一些对你有用的东西?
标签: ios ipad uicollectionview uicollectionviewcell