【问题标题】:Index 100 beyond bounds 0 ... 99 error in swipeDetected void索引 100 越界 0 ... 99 swipeDetected void 中的错误
【发布时间】:2012-07-21 01:11:57
【问题描述】:

在这里它工作正常。如果我尝试从索引中的第一个对象向右(向后)滑动,则不会发生任何事情。

- (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != 0)
    detailIndex--;  

Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}

但是当我在最后一个条目(nr 100)并向左滑动时,它崩溃了。这是左边的代码:

- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
    if (detailIndex != [detailsDataSource count])
        detailIndex++;


    Label.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Text"];
}

以及错误信息:

-[__NSArrayI objectAtIndex:]: 索引 100 超出范围 [0 .. 99]'

如何正确设置边界,使其不会滑过最后一个对象?

【问题讨论】:

    标签: iphone xcode arrays dictionary bounds


    【解决方案1】:
    - (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
    {
    
    if (detailIndex != 99)
        detailIndex++;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 2014-06-06
      • 2015-03-22
      • 2013-10-13
      • 2015-01-10
      • 2014-01-27
      • 1970-01-01
      相关资源
      最近更新 更多