嵌入父控制器时,[UICollectionViewData validateLayoutInRect:]中的断言失败

时间:2014-07-16 14:16:10

标签: ios objective-c uicollectionview uicollectionviewlayout

场景:

  1. 视图控制器 ControllerA ,其中包含集合视图。

  2. 此集合视图已在控制器A的 viewDidLoad 中获得自定义布局:self.collectionView.collectionViewLayout = [[MyCustomFlowLayout alloc]init];

  3. 如果将 ControllerA 加载到屏幕上,它可以正常工作,但是如果它被加载到另一个控制器中,比如说 ParentController ,则会产生一个断言错误:
  4.   

    * 断言失败 - [UICollectionViewData validateLayoutInRect:],/ SourceCache / UIKit_Sim / UIKit-2935.137 / UICollectionViewData.m:357

    我想张贴一张图片,但直到我有10个声望点才能发布。

    嵌入不同控制器时自定义布局存在一些问题。但我无法弄清楚是什么。有任何想法吗 ?

1 个答案:

答案 0 :(得分:0)

我知道这些问题已经过时了,但我想我会发布一个答案,因为我也遇到了这个问题。我在垂直滚动集合视图单元格中使用水平滚动集合视图。

在视图控制器中:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [self.collectionView performBatchUpdates:nil completion:^(BOOL finished)
    {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:kSaleSection];
        PromoFeedCollectionCell *cell = (PromoFeedCollectionCell *) [self.collectionView cellForItemAtIndexPath:indexPath];

        if (cell)
        {
            [cell resizeCellView];
        }
        finished = YES;
    }];
}

在我的PromoFeedCollectionCell中包含collectionView:

- (void)resizeCellView
{
    [self setNeedsLayout];

    [self.collectionView performBatchUpdates:nil completion:^(BOOL finished){

    finished = YES;
    }];
}