Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key to this was where the deletes and the inserts happened.</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Player *selectedPlayer = nil; //Get rid of any adjustment score row NSIndexPath *removeIndex; for (int i = 0; i &lt; [players count]; i++) { id player = [players objectAtIndex:i]; if ([player isKindOfClass:[NSString class]] &amp;&amp; [player isEqualToString:@"ADJUST_SCORE_ROW"]) { if (i == indexPath.row) { [scoreTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; return; //This is the case where the row that was selected was an adjustment row } removeIndex = [NSIndexPath indexPathForRow:i inSection:indexPath.section]; [players replaceObjectAtIndex:i withObject:@"DELETE_ME"]; break; } } selectedPlayer = [players objectAtIndex:indexPath.row]; [scoreTableView beginUpdates]; NSIndexPath *insertPath; if (removeIndex &amp;&amp; [removeIndex row] &lt; indexPath.row) { insertPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]; } else { insertPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; } HoleScore *holeScore = [[round scoreForPlayer:[players objectAtIndex:indexPath.row] holeGroup:self.holeGroupIndex andHole:hole.holeIndex] objectForKey:CURRENT_HOLE_SCORE]; if (holeScore == nil) { NSEntityDescription *scoreEntity = [NSEntityDescription entityForName:@"HoleScore" inManagedObjectContext:moc]; holeScore = [[HoleScore alloc] initWithEntity:scoreEntity insertIntoManagedObjectContext:moc]; [holeScore setPlayer:selectedPlayer]; [holeScore setHoleGroupIndex:[NSNumber numberWithInteger:holeGroupIndex]]; [holeScore setHoleIndex:[NSNumber numberWithInteger:hole.holeIndex]]; [holeScore setStrokes:[NSNumber numberWithInteger:[hole par]]]; [holeScore setPuts:[NSNumber numberWithInteger:2]]; HoleScoreCardTableViewCell *playerCell = (HoleScoreCardTableViewCell*)[scoreTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]; [playerCell setHoleScore:holeScore]; [round addScoresObject:holeScore]; NSError *error; [moc save:&amp;error]; if (error) { NSLog(@"Error saving: %@", error.localizedDescription); } } for (int i = 0; i &lt; [players count]; i++) { id player = [players objectAtIndex:i]; if ([player isKindOfClass:[NSString class]] &amp;&amp; [player isEqualToString:@"DELETE_ME"]) { [players removeObject:player]; break; } } if (removeIndex) { [scoreTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:removeIndex] withRowAnimation:UITableViewRowAnimationTop]; } [players insertObject:@"ADJUST_SCORE_ROW" atIndex:insertPath.row]; [scoreTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertPath] withRowAnimation:UITableViewRowAnimationTop]; [scoreTableView endUpdates]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload