Ich bin neu in der Programmierung. Der folgende Code funktioniert mit dem Durchstreichen einer Zeile, aber nach dem Aktualisieren wird die gesamte Zeilenliste wieder angezeigt. Ich habe folgenden Code:UItableview Swipe Löschen iOS 11 aktualisiert/lädt keine Daten
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@"DELETE"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSLog(@"index path of delete: %@", indexPath);
completionHandler(YES);
}];
delete.backgroundColor = [UIColor purpleColor]; //arbitrary color
UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete]];
swipeActionConfig.performsFirstActionWithFullSwipe = NO;
return swipeActionConfig;
}
Ich verwende folgende:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FCell = (favouriteCell *)[tableView dequeueReusableCellWithIdentifier:@"favouriteCell"];
FCell.selectionStyle=UITableViewCellSelectionStyleNone;
if (FCell == nil)
{
FCell = [[[NSBundle mainBundle]loadNibNamed:@"favouriteCell" owner:nil options:nil] objectAtIndex:0];
}
FCell.nameLBL.text=[[favDetails objectAtIndex:indexPath.row] valueForKey:@"name"];
FCell.poetLBL.text=[[favDetails objectAtIndex:indexPath.row] valueForKey:@"poet"];
return FCell;
}
Es scheint nicht, dass Sie die Zeile aus einer Datenquelle entfernen. Im completionHandler, in dem Sie den Indexpfad des Löschvorgangs protokollieren, müssen Sie diese Zeile aus Ihrer Datenquelle (Array usw.) entfernen. Andernfalls wird der Tisch erneut geladen, wenn er von der Datenquelle neu geladen wird. – Stephen
danke, was wäre der beste Weg, es zu tun? – Simi
Welche Struktur verwenden Sie als Datenquelle? Können Sie Code aus Ihrem cellForRowAtIndexPath freigeben? – Stephen