开发者社区> 问答> 正文

ios 我是新手,麻烦各位大牛人物帮忙看看:数组越界这个问题怎么处理

-(void)ResultView:(NSArray *)aData

{

examBrowseVc.title = self.strTitle;

  for(UIView *view in [self.scroll subviews]    

{

[view removeFromSuperview];
  

}
[resultVc_Marr removeAllObjects];

CGRect rect;

int x = 10;

int y = 10;

int width = 100;

int height = 120;

int margin = 30;

int numofrow = 6;

rect.origin.x = x;

rect.origin.y = y;

rect.size.width = width;

rect.size.height = height;

for (int i = 1; i <= aData.count; i++)

{

    
if (i>1)
     

{

rect.origin.x = rect.origin.x + rect.size.width + margin;

}

//换行坐标

if (i > 1 && i%numofrow == 1)

{

rect.origin.x = 10;

rect.origin.y = rect.origin.y + rect.size.height + margin;

}

NSDictionary *dict = [aData objectAtIndex:i-1];

TestResultUnitVc *resultIv = [[TestResultUnitVc alloc] initWithNibName:@"TestResultUnitVc" bundle:nil]
[resultIv.view setFrame:CGRectMake(rect.origin.x, rect.origin.y, resultIv.view.frame.size.width, resultIv.view.frame.size.height)];

[resultVc_Marr addObject:resultIv];

resultIv.nav = self.navigationController;

resultIv.qstRecord =aData;

resultIv.examBrowseVc = self.examBrowseVc;

resultIv.number = i;

if (self.view.tag == 1)

{

         
[resultIv.lbTimer setHidden:NO];
     

}
else
{

         
[resultIv.lbTimer setHidden:YES];
     

}

 [resultIv.numberLable setText:[NSString stringWithFormat:@"%d",i]];
     
     

NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];

NSString *s = [dict valueForKey:@"timer"];

      NSDate *d = [NSDate dateWithTimeIntervalSince1970:[s doubleValue]];
          

NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];

[formatter1 setTimeZone:GTMzone];

[formatter1 setDateFormat:@"00:mm:ss"];

          
NSString *showtimeNew = [formatter1 stringFromDate:d];
     

[resultIv.lbTimer setText:[NSString stringWithFormat:@"%@",showtimeNew]];

     
    
int state1 = [[dict valueForKey:@"ok_state"] integerValue];

if (state1 == 1)

{

         
[resultIv.imageStateView setImage:[UIImage imageNamed:@"result-right.png"]];
     

}

if (state1 == 2)

{

         
[resultIv.imageStateView setImage:[UIImage imageNamed:@"result-error.png"]];
     

}

if (state1 == 3)

{

         
[resultIv.imageStateView setImage:[UIImage imageNamed:@"result-unfinished.png"]];
         
      }
     

}

for (int i=0; i < resultVc_Marr.count; i++)

{

TestResultUnitVc *testResult = [resultVc_Marr objectAtIndex:i];

[self.scroll addSubview:testResult.view];

}

[scroll setContentSize:CGSizeMake(710,rect.origin.y+height+margin+20)];

}

Terminating app due to uncaught exception 'NSRangeException', reason: ' -[__NSArrayM objectAtIndex:]: index 42 beyond bounds [0 .. 41]'
* First throw call stack:
(0x7ea022 0x181ecd6 0x7d6d88 0x8720 0x9323 0x2c03c 0x11a0d 0x11c40 0x12bdeb6 0x7be936 0x7be3d7 0x721790 0x720d84 0x720c9b 0x1d8d7d8 0x1d8d88a 0x981626 0x1e1ed 0x2275)
terminate called throwing an exception(lldb)

红色标记的字体是否有冲突啊,但是我的程序运行起来正常显示,可就是到了最后数组越界。我不知道这个问题怎么处理?谢谢各位

展开
收起
杨冬芳 2016-06-30 11:49:23 2330 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载

相关实验场景

更多