これは 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;
}
これは私にとって新しいことなので、助けてください。
ありがとうございました。
よろしくお願いします。