【问题标题】:collectionviewCell not change when transition to other collectionviewController过渡到其他collectionviewController时collectionviewCell不会改变
【发布时间】:2013-10-30 08:37:41
【问题描述】:

我创建了 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 类。

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

【问题讨论】:

    标签: ios ios7 uicollectionview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 2017-02-09
      • 2017-01-12
      • 2018-03-21
      相关资源
      最近更新 更多