我创建了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也调用,但日志消息“重用CELL”告诉fullScreen CollectionView仍然使用旧的PhotoCell类。
我仍然不明白什么是问题。请帮帮我!
答案 0 :(得分:0)
答案是&#34;有点&#34;迟到但这可能对其他人有用。当您使用useLayoutToLayoutNavigationTransitions
视图控制器中的集合视图时,实际上会重用过渡。此集合视图具有不同的数据源和委托,这就是为什么FullScreenCollectionViewController
cellForRowAtIndexPath
未被调用的原因。看看这个类似的问题:
UICollectionView UseLayoutToLayoutNavigationTransitions with different datasources