Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes key references on delete #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions FXForms/FXForms.m
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,15 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
[section removeFieldAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

// Reload the rows that follow. This is necessary to update the field references on the cells (otherwise the keys
// are invalid which can lead to a crash).
NSMutableArray *indexPaths = [NSMutableArray new];
for (NSInteger i = indexPath.row; i < [section.fields count]; ++i)
{
[indexPaths addObject:[NSIndexPath indexPathForRow:i + 1 inSection:indexPath.section]];
}
[tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];

[tableView endUpdates];
}
}
Expand All @@ -2175,6 +2184,10 @@ - (void)tableView:(__unused UITableView *)tableView moveRowAtIndexPath:(NSIndexP
{
FXFormSection *section = [self sectionAtIndex:sourceIndexPath.section];
[section moveFieldAtIndex:sourceIndexPath.row toIndex:destinationIndexPath.row];

// Reload the table. This is necessary to update the field references on the cells (otherwise the keys
// are invalid which can lead to a crash).
[tableView reloadData];
}

- (NSIndexPath *)tableView:(__unused UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
Expand Down