Ich kämpfe von den letzten 2 Stunden. Warum die letzte Zeile nicht aus meiner Tabellenansicht gelöscht wird. Eine Zeile bleibt nur in der Tabellenansicht, die nicht entfernt wird. Obwohl ich das Objekt aus dem Array entfernt habe und nichts im Array ist.Problem und Absturz nach dem Löschen der letzten Zeile
Was ist ein Problem im Code?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
Geofencing *getObject = [routesArray objectAtIndex:indexPath.row];
[getObject deleteGeofencingFormDatabase:getObject.ah_routeid];
[routesArray removeObjectAtIndex:indexPath.row];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[routeTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self displayEmptyRouteAlert];
});
}
}
UPDATE 1:
-(void)displayEmptyRouteAlert
{
routesArray = [[Geofencing sharedInstance] fetchGeofencingFromDatabase];
if(routesArray.count > 0){
[routeTableView reloadData];
}
else{
NSString *messageStr = @"Let's start by creating new route.";
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"No route found"
message:messageStr
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *buttonAdd = [UIAlertAction actionWithTitle:@"Add New Route" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[self openToAddNewRoute];
}];
[alert addAction:buttonAdd];
UIAlertAction *buttoncancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
}];
[alert addAction:buttoncancel];
[self presentViewController:alert animated:YES completion:nil];
}}
tun neu laden Sie Tableview nach löschen? – Sofeda
Warum aktualisieren Sie Ihre 'tableView' nach einer Sekunde? Haben Sie versucht, die Anweisung "dispatch_after" zu entfernen? – Astoria
@SMi ja, ich habe versucht, mit Tabelle wieder zu laden – Ketan