开发者

UITableViewCell prevent deletion

I am looking for a way of preventing the deleting of one of my cells. (No delete button should appear next to the cell when the table view is in editing mode.)

How can this be mad开发者_Go百科e possible?


Implement editingStyleForRowAtIndexPath and return UITableViewCellEditingStyleNone for that row:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == sss && indexPath.row == rrr)
        return UITableViewCellEditingStyleNone;
    else
        return UITableViewCellEditingStyleDelete;
}


The accepted response works but is not the correct way to do it. There are two methods available: editingStyleForRowAtIndexPath and canEditRowAtIndexPath

editingStyleForRowAtIndexPath: Use when there are multiple different editing styles in the table

canEditRowAtIndexPath: Use when some rows should edit and some should not.

Therefore the correct way to implement your table delegate is:

- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == sss && indexPath.row == rrr)
    {
        return NO;
    }
    return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜