Here it works fine. If I try to swipe right (back) from first object in index nothing happens.
- (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != 0)
detailIndex--;
Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}
But when I’m on the last entry (nr 100) and swipes left, it crashes. Heres the code for left:
- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != [detailsDataSource count])
detailIndex++;
Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}
And error message:
-[__NSArrayI objectAtIndex:]: index 100 beyond bounds [0 .. 99]’
How can I set bounds correcly so it won’t swipe past the last object?
1 Answer