title: iOS Check If IndexPath is beyond bounds
body: <p>I wondered if anyone can shed any light, I have a list of selected players. Basically if a user taps on a indexRow that does not exist yet, I want to create it on tap.</p>
  
  <p>I am currently doing this to check;</p>
  
  <pre><code>if ([self.tableView cellForRowAtIndexPath:indexPath] == nil) {
  </code></pre>
  
  <p>It's just crashing with this;</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
  *** First throw call stack:
  </code></pre>
  
  <p>The exact method below;</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  
      if (indexPath.section == 2 &amp;&amp; tableView == self.tableView) {
  
          if (!self.usersSelectionArray || !self.usersSelectionArray.count || indexPath.row &lt; [self.usersSelectionArray count]) {
  
              // Create blank array and push to players
  
              // Push to Players Screen
              UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
              ListOfPlayersViewController *efvc = [storyboard instantiateViewControllerWithIdentifier:@"ListPlayers"];
              [self.navigationController presentViewController:efvc animated:YES completion:nil];
  
          } else {
  
          if ([self.tableView cellForRowAtIndexPath:indexPath] == nil) {
  
              // Push to Players Screen
              UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
              ListOfPlayersViewController *efvc = [storyboard instantiateViewControllerWithIdentifier:@"ListPlayers"];
              [self.navigationController presentViewController:efvc animated:YES completion:nil];
  
          } else {
  
              NSDictionary *cellDict = [self.usersSelectionArray objectAtIndex:indexPath.row];
  
              // Save Names
              [prefs setObject:[cellDict objectForKey:@"first_name"] forKey:@"teamFirstName"];
              [prefs setObject:[cellDict objectForKey:@"last_name"] forKey:@"teamLastName"];
              [prefs setObject:[cellDict objectForKey:@"avatar"] forKey:@"teamAvatar"];
  
              // Push to Info Screen
              UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
              PlayerInfoViewController *info = [storyboard instantiateViewControllerWithIdentifier:@"PlayerInfo"];
              [self.navigationController presentViewController:info animated:YES completion:nil];
          }
          }
      }
  
      if (indexPath.section == 2 &amp;&amp; tableView == self.awayTeamTableview) {
  
          NSDictionary *cellDict = [self.awaySelectionArray objectAtIndex:indexPath.row];
  
          // Save Names
          [prefs setObject:[cellDict objectForKey:@"first_name"] forKey:@"awayFirstName"];
          [prefs setObject:[cellDict objectForKey:@"last_name"] forKey:@"awayLastName"];
  
          // Push to Players Screen
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];
          ManualPlayerViewController *manual = [storyboard instantiateViewControllerWithIdentifier:@"ManualPlayer"];
          [self.navigationController presentViewController:manual animated:YES completion:nil];
      }
  
      int rowNumber = indexPath.row;
      [prefs setInteger:rowNumber forKey:@"rowNumber"];
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
  }
  </code></pre>