title: iOS NSRangeException, Index Beyond Bounds, NSMutable Array
body: <p>After inheirting an iPhone app project I'm tasked with the debugging of it after an update. Not an objective c programmer, I'm not sure where to start. Any help would be appreciated.</p>
  
  <p>Here is the debugging output:</p>
  
  <pre><code>2011-07-07 15:27:44.333 App[5836:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
  *** Call stack at first throw:
  (
      0   CoreFoundation                      0x013d0be9 __exceptionPreprocess + 185
      1   libobjc.A.dylib                     0x015255c2 objc_exception_throw + 47
      2   CoreFoundation                      0x013c66e5 -[__NSArrayM objectAtIndex:] + 261
      3   CollegeFootballAlerts               0x00034892 -[SMStandings tableView:cellForRowAtIndexPath:] + 397
      ...
  )
  terminate called after throwing an instance of 'NSException'
  </code></pre>
  
  <p>the breakpoint is here at teamsInfo = :</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString* cellIdentifier = @"TeamsInfoCell"; 
  
      SMStandingsTableViewCell * cell = (SMStandingsTableViewCell *)[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
      if( cell == nil ){
          [[NSBundle mainBundle] loadNibNamed:@"SMStandingsTableViewCell" owner:self options:nil];
          cell = standingsTableCell;
          standingsTableCell = nil;
      }
      SMTeamsInfo * teamInfo;
          NSMutableArray * teamsInGroup = [allGroups objectForKey:[allKeys objectAtIndex:indexPath.section]];
          NSLog(@"TEAMS IN GROUP %@ :: %d", teamsInGroup, indexPath.row);
          teamInfo = [teamsInGroup objectAtIndex:indexPath.row];
  
      [[cell teamName] setText:[teamInfo nameEN]];
      [[cell teamFlag] setImage:[teamInfo teamFlag]];
      NSString * str;
      if([segmentedControl selectedSegmentIndex] == 0) {               // for conference tab wonconf - lostconf  combination is used 
          str= [NSString stringWithFormat:@"%@",[teamInfo wonconf]];
          str = [str stringByAppendingString:@"-"];
          str = [str stringByAppendingFormat:@"%@",[teamInfo lostconf]];
      }else {                                                          // for overall tab wonconf - lostconf  combination is used 
          str= [NSString stringWithFormat:@"%@",[teamInfo wonall]];
          str = [str stringByAppendingString:@"-"];
          str = [str stringByAppendingFormat:@"%@",[teamInfo lostall]];
      }
  
      [[cell currentStanding ]setText:str];
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
      return cell;    
  }
  </code></pre>
  
  <p>and the numberOfRowsInSection method:</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      NSArray * array = [allGroups allKeys];
      NSLog(@"NO OF ROWS IN SECTION #%d : %d", section, [[allGroups objectForKey:[array objectAtIndex:section]] count]);  
      return [[allGroups objectForKey:[array objectAtIndex:section]] count];
  }
  </code></pre>
  
  <p>and the output of that method:</p>
  
  <pre><code>2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #1 : 7
  2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #0 : 6
  </code></pre>
  
  <p>not sure why section #1 coming in first... the number of rows is reverse. it should be 7 for section 0 and 6 for section 1 which seems like the root of the problem.</p>