我创建了一个CollectionView
控制并用图像填充它。现在我想在开始时滚动到特定索引处的项目。我已经尝试过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]
无论是错误还是功能,UIKit 都会在任何时候抛出此错误scrollToItemAtIndexPath:atScrollPosition:Animated
之前被调用UICollectionView
已列出其子视图。
作为解决方法,请将滚动调用移动到视图控制器生命周期中您确定它已经计算其布局的位置,如下所示:
@implementation CollectionViewControllerSubclass
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// scrolling here doesn't work (results in your assertion failure)
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
NSIndexPath *indexPath = // compute some index path
// scrolling here does work
[self.collectionView scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];
}
@end
至少,错误消息可能会更有帮助。我已经开了一个雷达://13416281 http://openradar.appspot.com/13416281;请欺骗。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)