Objective c 滑动删除

Objective c 滑动删除,objective-c,uitableview,swipe,delete-row,Objective C,Uitableview,Swipe,Delete Row,我有一个tableview和一个单元格:D,已选中。我用故事板创建了所有ui元素。 未在单元格的内容中放置视图 我使用SWTableViewCell实现了只需滑动删除,但除了在方法上设置断点外,其他一切似乎都可以正常工作 #pragma mark -SWTableViewDelegate- -(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)

我有一个tableview和一个单元格:D,已选中。我用故事板创建了所有ui元素。 未在单元格的内容中放置视图 我使用SWTableViewCell实现了只需滑动删除,但除了在方法上设置断点外,其他一切似乎都可以正常工作

#pragma mark -SWTableViewDelegate-

-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{

    NSIndexPath *path=[self.table indexPathForCell:cell];
    [anArray removeObjectAtIndex:path.row];
    [self.table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
}
这将帮助你理解我在这里所做的一切

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

    SWTableViewCell *cell=(SWTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    if (!cell)
    {

        NSMutableArray *rightUtilityButtons = [NSMutableArray new];
        [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithRed:1.0f
                                                                      green:0.231f
                                                                       blue:0.188
                                                                      alpha:1.0f]
    title:@"Delete"];

        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell" containingTableView:_table leftUtilityButtons:nil rightUtilityButtons:rightUtilityButtons];
    }

    NSMutableDictionary *deDict=[[NSMutableDictionary alloc]initWithDictionary:[anArray objectAtIndex:indexPath.row]];

    cell.textLabel.text= [deDict objectForKey:@"Name"];

    return cell;
}

然而,我并没有得到任何错误,因为当我试图在模拟器上滑动时,它根本不起作用

无需使用SWTableViewCell,只需覆盖UITableView委托的以下内置方法,即可支持条件编辑和滑动删除

用于条件编辑-可选-

用于滑动以删除


它们不是UITableView方法,您不会重写它们。它们是委托方法。我现在正在做CommittedIttingStyle和TitleForDeleteConfirmationButtonFrrowatInXPath,要想看到它工作,那么没关系,不用担心,只需从右向左滑动,你就会看到delete按钮,当它按下时,它会按照CommittedIttingStyle执行操作如果这有助于找到你的解决方案,请接受我的Ans&别忘了向上推问题是,我在故事板上分配了代理,而不是以编程方式分配的
//Override this method only if you are going to be returning NO for some items. 
//By default, all items are editable.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return YES if you want the specified item to be editable.
    return YES;
}
// Override to support editing the table view.
// for swipe to delete
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
    }    
}