2

サブクラス化されたCollectionViewCelliには、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;
}

スクロールするまではすべて問題ないようです。原因となる可能性のあるアイデアはありますか?

スクロールする前に 下にスクロール正しくレンダリングされたビュー する下に 下にスクロール スクロールする 上にスクロールして戻る

4

1 に答える 1

1

問題は、セル内のサブビューのサイズが変更されなかったことです。最も簡単な解決策 (少なくとも UILabels の場合) は、autoresizingmask を次のように設定することです。UIViewAutoresizingFlexibleHeight.

于 2013-01-04T10:00:51.887 に答える