我创建了一个CollectionView
控制和处理图像填充它。现在我想在开始时滚动到特定索引处的项目。我试过scrollToItemAtIndexPath
如下:的Xcode CollectionViewController scrollToItemAtIndexPath不工作
[self.myFullScreenCollectionView scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
但是,我得到以下异常。任何人都可以指导我在哪里出错。
2013-02-20 02:32:45.219 ControlViewCollection1[1727:c07] *** Assertion failure in
-[UICollectionViewData layoutAttributesForItemAtIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17
/UICollectionViewData.m:485 2013-02-20 02:32:45.221 ControlViewCollection1[1727:c07] must return a
UICollectionViewLayoutAttributes instance from -layoutAttributesForItemAtIndexPath: for path
<NSIndexPath 0x800abe0> 2 indexes [0, 4]
不要忘记垂直和水平滚动的位置值:http://stackoverflow.com/a/18227362/989896 – Alena 2013-08-14 08:59:44
这个答案救了我这么多发拉,谢谢!通过移动我的图像大小更新和重新加载代码到viewDidLayoutSubviews,我也摆脱了恼人的集合视图警告,所以我负债累累。 – phatmann 2013-09-26 20:48:17
我把它放在viewDidApper而不是viewDidLayoutSubviews中,因为我只想滚动一次,并不是每次布局重新计算,但是你保存了我的一天。 – Vaseltior 2015-03-17 11:37:45