在 uitableveiw 中滑动,删除按钮不出现。另外,当我快速滑动时,会出现删除按钮

swipe in uitableveiw ,Delete button does not appear. Also when I swipe it very fast, delete button appears

我正在尝试在 UITableView 中实现滑动删除。 ViewController 不包含平移手势或任何其他功能。包含 UITableViewviewController 在选择侧面菜单时被按下。以下是我使用的代码。

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableViewRefresh.dataSource = self;
    self.tableViewRefresh.delegate = self;
    // Do any additional setup after loading the view.
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *simpleTableIdentifier = @"cell1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 1.0f;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

滑动时没有出现删除按钮。但是,当我快速滑动它时,会出现删除按钮。任何帮助将不胜感激。

试试这个代码。您可以在滑动 uitableviewcell 时根据需要添加 n 个按钮。确保 return return 语句 (return @[deleteAction, someOtherButtonName])

中的所有按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {   

    // Delete button

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

        // Action for delete button

    }];

    deleteAction.backgroundColor = [UIColor redColor];

    return @[deleteAction];

}

我也遇到了同样的问题,通过禁用侧边菜单的 panMode 解决了这个问题。如果您使用的是 MFSideMenu,请查看下面的代码-

MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
                                                    containerWithCenterViewController:centerViewController
                                                    leftMenuViewController:leftViewController
                                                    rightMenuViewController:nil];

container.panMode = MFSideMenuPanModeNone;

我假设 tableview 滑动删除的默认功能被相同 class 或父 classes.Please 检查当前 class、父 class 或classes 中使用的库。

感谢大家的支持

问题已解决。

我一直在使用 LGMenuController class 在 App 上实现导航抽屉。 class 在整个应用程序中通过滑动手势使用手势识别功能 show/close 侧面菜单。

table 视图的滑动删除的默认功能似乎被 LGMenuController class 中使用的手势识别器覆盖了。一旦手势识别完全禁用,UITableView 的滑动删除功能就可以正常工作了。