【发布时间】:2013-08-13 05:38:23
【问题描述】:
这是我为 CollectionViewCustomCells 设置动画的代码。
-(void)viewDidAppear:(BOOL)animated{
rowIndex = 0;
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(targetMethod)
userInfo:nil
repeats:YES];
}
-(void)targetMethod
{
[self.offerCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:1]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];
rowIndex=(rowIndex<parserDataContentArrayForExhibitor.count-1)?(rowIndex+1):0;
// if (rowIndex == parserDataContentArrayForExhibitor.count) {
// rowIndex = 0;
// }
}
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'attempt to scroll to invalid index path: <NSIndexPath 0xab55110> 2 indexes [1, 0]'
每次运行我的应用程序时都会遇到此异常。 但有时应用运行良好。 我相信有一些泄漏或某种东西。 我尝试了什么:当我用谷歌搜索时,我发现这种错误是因为如果我写了一个不存在的部分并且第一部分的部分索引为 0。
所以我将目标方法更改为:
-(void)targetMethod
{
[self.offerCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:0]
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];
rowIndex=(rowIndex<parserDataContentArrayForExhibitor.count-1)?(rowIndex+1):0;
// if (rowIndex == parserDataContentArrayForExhibitor.count) {
// rowIndex = 0;
// }
}
但是同样的事情发生了,异常的参数稍有变化。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'attempt to scroll to invalid index path: <NSIndexPath 0xab22ea0> 2 indexes [0, 0]'
部分代码:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
请帮帮我,因为这对我来说有点新鲜。
谢谢。
最好的问候。
【问题讨论】:
-
你有多少个部分?部分从索引 0 开始。
-
@nikhitadkslfslg : 我只有一节。
-
@nikhitadkslfslg:请检查已编辑的问题。
-
inSection=0很好。问题可能出在rowIndex。 -
@nikhitadkslfslg :所以我需要将 rowIndex 更改为 1 还是可能用 VDL 或任何其他方法编写它???
标签: ios exception uicollectionview