__NSArrayI objectAtIndex:]:index 2超出objective-c中的bounds [0 .. 1]

时间:2017-09-21 08:43:15

标签: ios xcode

  if(counter>=keys.count){

        NSLog(@"finished");
        [_images removeFromSuperview];
      //  [_alphabetsShowImageView removeFromSuperview];
        [_speakerOrMicImageView removeFromSuperview];
        UIImageView *congratzView = [[UIImageView alloc]initWithFrame:self.view.frame];
        congratzView.image = [UIImage imageNamed:@"congratulation.png"];
        [self.view addSubview:congratzView];

    }

    else{


           arrVal = [dictAlpha objectForKey:keys[i]];


                 if(j>=arrVal.count)

                     {
                         NSLog(@"finished");
                         [_alphabetsShowImageView removeFromSuperview];
                         [_speakerOrMicImageView removeFromSuperview];
                         UIImageView *congratzView = [[UIImageView alloc]initWithFrame:self.view.frame];
                         congratzView.image = [UIImage imageNamed:@"congratulation.png"];
                         [self.view addSubview:congratzView];
                       //  [self performSelector:@selector(navNew) withObject:nil afterDelay:3];

                     }
                     else
                     {
                         [commonFunctionObject textToSpeechAction:arrVal :j :_alphabetsShowImageView :_speakerOrMicImageView :isMicPresent];
                         [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(ActionToCkeckRecordCompletion) userInfo:nil repeats:YES];
                     }





           }








}

输出我需要 -     计数器&LT = keys.count  然后它必须输入if语句条件, 然后j< = arrval.count     然后输入else条件。或者输入if条件循环。 然后如果计数器> = keys.count 然后它必须输入if语句条件

1 个答案:

答案 0 :(得分:0)

您正在使用counter进行迭代,但是您正在使用不同的变量访问数组元素。

您的错误显然意味着计数器和访问者i& j可能或可能不等于反制。

您的代码有资格称为快速遍历。您可能还会考虑这种情况的枚举,这将使您免于维护计数器的痛苦;你也可以避免if-else语句。帮助人们保持代码简单!

for(NSString* key in dictAlpha) {
    arrVal= [dictAlpha objectForKey:key];
}