Ios UICollectionView setContentOffset断言失败

Ios UICollectionView setContentOffset断言失败,ios,objective-c,xcode,uicollectionview,Ios,Objective C,Xcode,Uicollectionview,我使用的是Xcode 6和iOS 8。 我想在每次加载视图控制器时设置集合视图的内容偏移量 CGFloat offsetY = [self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath].frame.origin.y; [self.collectionView setContentOffset:C

我使用的是Xcode 6和iOS 8。 我想在每次加载视图控制器时设置集合视图的内容偏移量

CGFloat offsetY = [self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath].frame.origin.y;    
[self.collectionView setContentOffset:CGPointMake(0, MIN(self.collectionView.contentSize.height-self.collectionView.bounds.size.height, offsetY-headerHeight)) animated:NO];
但我收到此错误:
***在-[UICollectionViewData validateLayoutInRect:]中断言失败。

我所尝试的:
[self.collectionView prepare layout]

将此代码放入
-viewdilayoutsubviews
中不会改变任何内容。

您将contentOffset的Y值设置为什么确切值?你试过调试它吗?