我是編程新手。下面的代碼使用滑動刪除一行,但在刷新所有行列表後出現。 我有以下代碼:UItableview滑動刪除iOS 11不刷新/重新加載數據
- (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;
}
我使用如下:
- (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;
}
它似乎沒有從任何數據源中刪除該行。 在您正在記錄刪除的索引路徑的completionHandler中,您需要從數據源(數組等)中刪除該行。否則,當你的表從數據源重新加載時,它會重新出現。 – Stephen
謝謝,最好的辦法是做什麼? – Simi
你用什麼結構作爲數據源?你能分享你的cellForRowAtIndexPath的一些代碼嗎? – Stephen