首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UItableview滑动删除iOS 11不刷新/重新加载数据

UItableview滑动删除iOS 11不刷新/重新加载数据
EN

Stack Overflow用户
提问于 2017-09-22 18:31:48
回答 1查看 2K关注 0票数 2

我对编程很陌生。下面的代码与swipe一起工作,删除一行,但在刷新后,所有行列表将返回。我有以下代码:

代码语言:javascript
复制
- (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;

}

我使用的方法如下:

代码语言:javascript
复制
- (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;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-28 13:01:15

在记录删除索引路径的completionHandler中,需要从数据源(数组等)中删除该行。否则,当您的表从数据源重新加载时,它将重新出现。

您的trailingSwipeActionsConfigurationForRowAtIndexPath代码应该如下所示:

代码语言:javascript
复制
    - (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);
[favDetails removeObjectAtIndex:indexPath.row];                                                  
completionHandler(YES);


                                                                           }];
         delete.backgroundColor = [UIColor  purpleColor]; //arbitrary color

        UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete]];
        swipeActionConfig.performsFirstActionWithFullSwipe = NO;

        return swipeActionConfig;

    }

这将从数据源中删除对象,因为从表中直观地删除了行。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46371146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档