【问题标题】:make UITableViewCell selectable only while editing仅在编辑时使 UITableViewCell 可选
【发布时间】:2013-12-31 22:06:55
【问题描述】:

我有一个 UITableView,其中 selectionStyle 设置为 UITableViewCellSelectionStyleNone,因为我不希望在点击单元格时有任何可见的变化,但是当它处于编辑模式时,我确实希望单元格是可选的,因此每个选中的都会出现复选标记行,但使用 UITableViewCellSelectionStyleNone 似乎可以防止出现复选标记。

有什么想法可以做到这一点吗?

谢谢...

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    您是否尝试过像这样设置 tableView 的选择属性:

    tableView.allowsMultipleSelection = NO;
    tableView.allowsMultipleSelectionDuringEditing = YES;
    tableView.allowsSelection = NO;
    tableView.allowsSelectionDuringEditing YES;
    

    如果您想要更精细地控制何时允许选择,您可以在 UITableView 委托中覆盖 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath。文档指出:

    Return Value
    An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don't want the row selected.
    

    如果您不希望选择发生,您可以让此方法返回 nil。

    【讨论】:

    • 这正是我最终所做的。这非常有效。 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView.isEditing) { return indexPath; } else { return nil; } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多