The following code is used to record the selected rows when you click a row in the selected tableview. When you scan and delete a row on the left, it deletes the row of data and updates the data in Uitableview.
@interface DummyTableViewController : UITableViewController@property (nonatomic, strong) NSMutableArray *items;@end@implementation DummyTableViewController- (instancetype)initWithStyle:(UITableViewStyle)style{ self = [super initWithStyle:style]; if (self) { _items = [ @[ @"A", @"B", @"C", @"D", @"E" ] mutableCopy]; } return self;}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.items count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; cell.textLabel.text = self.items[indexPath.row]; return cell;}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { [self.items removeObjectAtIndex:indexPath.row]; [tableView reloadData]; }}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"Row %@ tapped.", self.items[indexPath.row]);}
In the ios6 environment, the previous Code follows the expectation described above. However, in the ios7 environment, I performed the following operations: When a row in tableview is deleted and updated to tablview, The Click Event of the next row of the deleted row is ignored, as a result, clicking this row does not respond. It's strange, isn't it? The reason is explained below.
When a row in tableview is selected and deleted, tableview will be in the editing status. Therefore, you need to change the status in tableview to the selection mode. The code for changing this mode is as follows:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { [self.items removeObjectAtIndex:indexPath.row]; // Turn off editing state here tableView.editing = NO; [tableView reloadData]; }}
Note: Due to my limited level, translation errors are inevitable. If you have any errors, please correct them and modify them as soon as possible.
Original article: http://stackoverflow.com/questions/19364409/uitableviewcontroller-ignores-tap-after-deleting-row-in-ios7