美文网首页
UITableView删除

UITableView删除

作者: 守护地中海的花 | 来源:发表于2020-06-30 11:40 被阅读0次

    左滑删除


    QQ20200630-104442-HD.gif
    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return @"删除";
    }
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return UITableViewCellEditingStyleDelete;
    }
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            NSLog(@"删除");
        }
    }
    

    左滑删除2

    QQ20200630-105304-HD.gif
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES;
    }
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return UITableViewCellEditingStyleDelete;
    }
    - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        WK(weakSelf)
        UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
            NSLog(@"删除");
        }];
        deleteAction.backgroundColor = AppButtonNormalColor;
        UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"取消" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
            NSLog(@"取消");
        }];
        cancelAction.backgroundColor = kColor152;
        return @[deleteAction,cancelAction];
    }
    

    bug

    有时候左滑失效 因为扩大滑动范围 所以还是不要加了

    dispatch_async(dispatch_get_main_queue(), ^{
        //留着扩大滑动范围用
        self.mainView.contentSize = CGSizeMake(0, self.mainView.contentSize.height + 94*ADAPTER_WIDTH);
    });
    

    相关文章

      网友评论

          本文标题:UITableView删除

          本文链接:https://www.haomeiwen.com/subject/bibtqktx.html