大家好,我目前正试图阻止一个tableviewcell可编辑。
但是我在Internet上找到的解决方案无法正常工作。
这是我使用的代码:

- (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的editstyle,则删除徽章:

- (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];
}


那么我在做什么错呢?

最佳答案

您还需要添加编辑样式

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

}

关于ios - 禁止一个UITableViewCell可编辑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14354261/

10-12 00:34
查看更多