【问题标题】:UITableViewCell: Allowing Selective DeletionUITableViewCell:允许选择性删除
【发布时间】:2010-05-29 11:13:58
【问题描述】:

我有一个表格视图并希望允许对所有单元格重新排序,但是我不希望允许删除某些单元格。当 UiTableView 进入删除模式时,我不希望红色的“-”按钮出现在左侧,也不希望滑动手势调出这些单元格的删除按钮,但希望它发生在其他单元格上.有任何想法吗?

【问题讨论】:

    标签: ios iphone uitableview cocoa-touch


    【解决方案1】:
    - (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;
        }
    }
    

    当然,这会在“-”按钮所在的位置留下一个空白区域,但不允许删除。而且也不允许滑动删除。

    【讨论】:

    • 实施- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 以防止缩进,如果你不想这样做:)
    【解决方案2】:

    实现:

    // 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;
    }
    

    【讨论】:

    • 这将阻止单元格重新排序,我只想停止删除并允许重新排序。
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 2020-10-31
    相关资源
    最近更新 更多