首先保证:

1 self.tableView.allowsSelection = YES;  // 默认是 YES
2 self.tableView.allowsSelectionDuringEditing = YES;

UITableView中的声明:

1 @property(nonatomic) BOOL allowsSelection __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  // default is YES. Controls whether rows can be selected when not in editing mode
2 @property(nonatomic) BOOL allowsSelectionDuringEditing;                                     // default is NO. Controls whether rows can be selected when in editing mode

===========================================================================================

对于具体的UITableViewCell在不同时期的可选性单独控制,假设根据 [Edit/Done] editButtonItem 控件分别控制cell0,cell1:

实现 UITableView Delegate 中的 tableView:willSelectRowAtIndexPath: 方法

 1 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
 2 {
 3     NSInteger row = indexPath.row;
 4     BOOL editing = self.editing;
 5     
 6     if ( (editing && row == 0) || (!editing && row == 1) ) {
 7         [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
 8         return nil;
 9     }
10     return indexPath;
11 }

参考:UITableView Setting some cells as “unselectable”

相关文章:

  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-11-15
  • 2022-03-05
猜你喜欢
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2022-02-05
  • 2021-10-03
  • 2021-12-10
  • 2021-05-26
相关资源
相似解决方案