Iphone 索引100超出边界0。。。99 swipeDetected void中的错误
在这里它很好用。若我尝试从索引中的第一个对象向右(向后)滑动,则不会发生任何事情Iphone 索引100超出边界0。。。99 swipeDetected void中的错误,iphone,xcode,arrays,dictionary,bounds,Iphone,Xcode,Arrays,Dictionary,Bounds,在这里它很好用。若我尝试从索引中的第一个对象向右(向后)滑动,则不会发生任何事情 - (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender { if (detailIndex != 0) detailIndex--; Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"]; } 但当我在最后一个条目(NR10
- (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != 0)
detailIndex--;
Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}
但当我在最后一个条目(NR100)上向左滑动时,它崩溃了。这是左边的代码:
- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != [detailsDataSource count])
detailIndex++;
Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}
和错误消息:
-[\uu NSArrayI objectAtIndex:]:索引100超出范围[0..99]'
如何正确设置边界,使其不会掠过最后一个对象
- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != 99)
detailIndex++;
}