代码之家  ›  专栏  ›  技术社区  ›  Aran Mulholland JohnnyAce

UITableViewCell:允许选择性删除

  •  4
  • Aran Mulholland JohnnyAce  · 技术社区  · 16 年前

    我有一个表视图,并希望允许所有单元格重新排序,但有些单元格我不想被允许删除。当UiTableView进入删除模式时,我不希望红色的“-”按钮出现在左侧,也不希望滑动手势出现这些单元格的删除按钮,但希望其他单元格也出现这种情况。有什么想法吗?

    2 回复  |  直到 10 年前
        1
  •  7
  •   Aran Mulholland JohnnyAce    16 年前
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        //if we cant delete the object represented at the index path
        if ([[tableViewObjectsArray objectAtIndex:indexPath.row] canBeDeleted] == NO){
            return UITableViewCellEditingStyleNone;
        }
        //otherwise allow the deletion
        else{
            return UITableViewCellEditingStyleDelete;
        }
    }
    

    当然,这会在“-”按钮应该在的地方留下一个空白,但它不允许删除。而且也不允许刷卡删除。

        2
  •  2
  •   jrtc27    16 年前

    实施:

    // Override to support conditional editing of the table view.
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        // Return NO if you do not want the specified item to be editable.
        return YES;
    }