Swipe To Delete TableView Row

后端 未结 8 940
暖寄归人
暖寄归人 2020-12-24 06:10

I have my array:

self.colorNames = [[NSArray alloc] 
initWithObjects:@\"Red\", @\"Green\",
@\"Blue\", @\"Indigo\", @\"Violet\", nil];

I\'ve

相关标签:
8条回答
  • 2020-12-24 07:11

    This is what worked for me

    -(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    
        if (editingStyle == UITableViewCellEditingStyleDelete){
            Comment *comment = [self.commentArray objectAtIndex:indexPath.row];
            dispatch_async(kBgQueue, ^{
                if([self.thePost deleteCommentForCommentId:comment.commentId]){
                    if (indexPath.row < self.commentArray.count) {
                        [self.commentArray removeObjectAtIndex:indexPath.row];
                    }
                    dispatch_async(dispatch_get_main_queue(), ^{
    
                        [self.tvComments reloadData];
                    });
                }
            });
        }
         [self.tvComments reloadData];
    }
    
    0 讨论(0)
  • 2020-12-24 07:12

    Swift 4 Version :

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let delete = UITableViewRowAction(style: .destructive, title: "delete") { (action, indexPath) in
            // delete item at indexPath
    
        }
        return [delete]
    }
    
    0 讨论(0)
提交回复
热议问题