0

我试过了,但刷卡不会触发 tableView:willBeginEditingRowAtIndexPath: !并且删除按钮永远不会出现,是否有解决方法?

编辑:这是我的实现

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

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView beginUpdates];
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        if(_itemsArray == nil)
            NSLog(@"\n\nNIL ARRAY\n\n");
        NSLog(@"\nindexPath.row = %d\nItemsArray Count:%d",indexPath.row,_itemsArray.count);
        int row = [[[_itemsArray objectAtIndex:indexPath.row]valueForKey:@"itemRow"] integerValue];
        [_itemsArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [[self delegate]didDeletedBillItemRow:row];
    }

    [tableView endUpdates];
}
4

1 回答 1

7

tableView:willBeginEditingRowAtIndexPath:不是处理这个问题的正确地方。从官方文档中,您需要在 UITableViewController 中实现此方法:

注意:要启用表格视图的滑动删除功能(其中用户水平滑动一行以显示删除按钮),您必须实现tableView:commitEditingStyle:forRowAtIndexPath: 方法。

就像这样:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //add code here for when you hit delete
    }    
}
于 2013-02-13T08:25:33.600 回答