1

我创建了 2 个 UICollectionView 类,每个类使用 2 个不同的 UICollectionViewCell

@interface PhotosCollectionViewController : UICollectionViewController
@interface FullScreenCollectionViewController : UICollectionViewController

@interface PhotoCell : UICollectionViewCell
@interface FullPhotoCell : UICollectionViewCell<UIScrollViewDelegate>

PhotosCollectionViewController.m中,我注册 PhotoCell 类并在 didSelect 时选择下一个视图控制器是 FullScreenCollectionViewController

//Register Cell
-(id)initWithCollectionViewLayout:(UICollectionViewFlowLayout *)layout{
    if (self = [super initWithCollectionViewLayout:layout])
    {        
        [self.collectionView registerClass:[PhotoCell class] forCellWithReuseIdentifier:CELL_ID];
    }
    return self;
}
//dequence resuse code
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCell* cell = (PhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_ID forIndexPath:indexPath];
    NSLog(@"reuse CELL");
    FICDPhoto *photo = [_photos objectAtIndex:indexPath.row];
    cell.imageView.image = [photo sourceImage];
    return cell;
}
//Next ViewController transition code
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UIViewController *vc = [self nextViewControllerAtPoint:CGPointZero];
    [self.navigationController pushViewController:vc animated:YES];
}


-(UICollectionViewController*)nextViewControllerAtPoint:(CGPoint)p
{
    FullScreenCollectionViewController* nextCollectionViewController = [[FullScreenCollectionViewController alloc] initWithCollectionViewLayout:[[FullScreenFlowLayout alloc] init]];

    nextCollectionViewController.useLayoutToLayoutNavigationTransitions = YES;

    nextCollectionViewController.title = @"FullScreen";
    return nextCollectionViewController;

}

FullScreenCollectionViewController中,我注册了 FullPhotoCell 类

[self.collectionView registerClass:[FullPhotoCell class] forCellWithReuseIdentifier:CELL_ID_FULL];

但序列码从不调用

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FullPhotoCell* cell = (FullPhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_ID_FULL forIndexPath:indexPath];
    NSLog(@"Reuse FULL Cell");
    FICDPhoto *photo = [_photos objectAtIndex:indexPath.row];
    cell.imageView.image = [photo sourceImage];
    return cell;
}

应用新布局,FullScreenCollectionViewController 的 viewDidload 也被调用,但日志消息“reuse CELL”告诉 fullScreen CollectionView 仍然使用旧的 PhotoCell 类。

我还是不明白有什么问题。请帮我!

4

1 回答 1

0

答案“有点”晚了,但这可能对其他人有用。当您使用useLayoutToLayoutNavigationTransitions来自视图控制器的集合视图时,启动转换实际上是重用的。此集合视图具有不同的数据源和委托,这就是不调用FullScreenCollectionViewController's的原因。cellForRowAtIndexPath看看这个类似的问题: UICollectionView UseLayoutToLayoutNavigationTransitions with different datasources

于 2017-09-24T10:49:52.450 回答