小编Bri*_*lva的帖子

编辑时的UITableView每单元格选择模式

在我UITableView进入编辑模式时,我只想选择几个单元格.我知道UITableView班级有财产allowsSelectionDuringEditing,但这适用于整体UITableView.我没有看到任何相关的委托方法来基于每个单元格进行设置.

我能提出的最佳解决方案是设置allowsSelectionDuringEditingYES.然后,didSelectRowAtIndexPath如果表视图正在编辑,则过滤掉任何不需要的选择.此外,在cellForRowAtIndexPath,将这些单元格更改selectionStyle为"无".

这个问题是进入编辑模式不会重新加载UITableViewCells,所以它们selectionStyle不会改变,直到它们滚动到屏幕外.所以,在setEditing中,我还必须迭代可见单元格并设置它们selectionStyle.

这有效,但我只是想知道这个问题是否有更好/更优雅的解决方案.附上我的代码的基本大纲.任何建议都非常感谢!谢谢.

- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

    if (self.editing && ![self _isUtilityRow:indexPath]) return;
    // Otherwise, do the normal thing...
}

- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

    // UITableViewCell* cell = ...

    if (self.editing && ![self _isUtilityRow:indexPath])
    {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else
    {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    return cell;
}

- (void) setEditing:(BOOL)editing animated:(BOOL)animated { …
Run Code Online (Sandbox Code Playgroud)

iphone selection uitableview

5
推荐指数
1
解决办法
1928
查看次数

标签 统计

iphone ×1

selection ×1

uitableview ×1