2014-07-16 28 views
2

場景:斷言失敗 - [UICollectionViewData validateLayoutInRect:]而嵌入父控制器

  1. 視圖控制器ControllerA在它的集合圖。

  2. 這一系列觀點中viewDidLoad中控制器A的被賦予了一個自定義佈局:self.collectionView.collectionViewLayout = [[MyCustomFlowLayout alloc]init];

  3. 如果ControllerA加載到它工作正常,但如果它被加載另一個控制器裏面的屏幕,說ParentController它提供了一個斷言錯誤爲:

*作爲在插入可以失敗 - [UICollectionViewData validateLayoutInRect:],/SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionViewData.m:357

我想張貼圖片,但不能等到我有10點聲望。

嵌入到不同的控制器時,自定義佈局存在一些問題。但我無法弄清楚什麼。有任何想法嗎 ?

回答

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; 
    }]; 
}