当TableView setEditing设置时,不能selectUITableViewCell

我希望能够select多行,如下面显示的默认邮件应用程序:

在这里输入图像说明

我有一个名为编辑的button调用

[self.myTableView setEditing:YES animated:YES] 

在这里输入图像说明

编辑button成功地显示了如上所示的邮件应用程序在单元格左侧的圆圈。 但是,当我真的select其中一个行时,什么都不会发生。 红色复选标记不会像我所期望的那样出现在圆圈中。 为什么不显示红色复选标记?

 #pragma mark - UITableViewDataSource Methods - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"]; } cell.textLabel.text = @"hey"; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } #pragma mark - UITableViewDelegate Methods - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return 3; } #pragma mark - Private Methods - (IBAction)editButtonTapped:(id)sender { if (self.myTableView.editing) { [self.myTableView setEditing:NO animated:YES]; } else { [self.myTableView setEditing:YES animated:YES]; } } 

在编辑模式下,您必须明确地将select设置为启用:

 [self.tableView setAllowsSelectionDuringEditing:YES]; 

要么

 [self.tableView setAllowsMultipleSelectionDuringEditing:YES]; 

根据文档 :这些属性默认设置为NO

如果此属性的值为YES,则用户可以在编辑过程中select行。 默认值是NO。 如果要限制单元格的select,请使用allowedSelection。

此外,下面的代码片段可能会导致您的select出现问题,因为一旦select了它,它立即取消select该行。

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; }