0

内部に UICollectionView を持つ UITableViewCell があります。私のカスタム UITableViewCell は、UICollectionView のデータソースとメソッドを担当します。cellForItemAtIndexPath にログを追加する場合を除いて、すべてが完全に機能します。すべての UICollectionViewCells が一度に読み込まれることがわかります。そのため、下にスクロールすると、遅延/遅延読み込みが発生します。

これがカスタム UITableViewCell での私のログです

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView                cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Loading cell: %i", indexPath.row);
}

tableViewCell の高さは、UICollectioNView が処理する必要がある項目に基づいて自動的に計算されます。したがって、ViewController の tableview メソッドでは次のようになります。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //return dynamically the height based on the items to show in the collectionview.
}

これが私の問題であり、遅延読み込みを行わない理由だと思います。これを簡単に修正する方法はありますか? または、これは方法ですか:

UITableViewCell に UICollectionView を配置する

ソース: http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell

これにより、遅延読み込みは UITableView によってのみ処理され、UICollectionView では処理されません。

これが私のカスタム UITableViewCell の完全なコードですが、ご覧のとおり、これは特別なことではありません。

@implementation PeopleJoinedThisPlaceCell

@synthesize people = _people;

- (void)awakeFromNib
{
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor clearColor];
}

- (void)setPeople:(NSArray *)people
{
    _people = people;
    [collectionView reloadData];
}


#pragma mark - CollectionViewController delegate methods

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    if(_people == NULL) return 0;
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if(_people == NULL) return 0;
    return _people.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView_ cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Loading cell: %i", indexPath.row);
    ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"People" forIndexPath:indexPath];

    PFObject *userPlace = [_people objectAtIndex:indexPath.row];
    PFUser *user = [userPlace objectForKey:UserClassName];
    [cell.BackgroundImageView setImage:[UIImage imageNamed:@"photo-big-bg"]];
    [cell.ImageLoader startAnimating];
    [[UserPhotos sharedInstance] getCachedSmallPhotoForUser:user withBlock:^(UIImage *image, NSError *error) {
        [cell.ImageView setImage:image];
        [cell.ImageLoader stopAnimating];
    }];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView_ didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    PFObject *userPlace = [_people objectAtIndex:indexPath.row];
    [_delegate gotoUserProfile:userPlace];
}

@end
4

0 に答える 0