0

嘿伙计们,我目前正试图阻止一个 tableviewcell 可编辑。但是我在互联网上找到的解决方案无法正常工作。这是我使用的代码:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        // Return NO if you do not want the specified item to be editable.

        if (indexPath.section == 1) {
            if (indexPath.row == self.results.count+1) {
                return NO;
            }
        }

        return YES;
}

这里的问题是 tableview 单元格不再可编辑,但如果我像这样启用我的 tableview 的编辑样式,它仍然显示红色删除徽章:

- (void) barButtonItemEditPressed: (id) sender
{
    [self.navigationController setToolbarHidden:NO animated:YES];
    [self.tableView setEditing:YES animated:YES];
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:self.barButtonItemDone, nil] animated:YES];
    [self.navigationItem setLeftBarButtonItem:self.barButtonItemCancel animated:YES];
}

那么我做错了什么?

4

1 回答 1

2

您还需要添加编辑样式

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

}
于 2013-01-16T08:48:25.087 回答