Consider the following plain and simple UITableViewController: when you tap a row, it logs the selected row, and when you swipe and delete, it removes an item in the model and reloads the data.
@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 iOS6, this all works as expected, but in iOS7 I get the following behavior: after a row has been removed and the data has been reloaded, the first next tap on a table cell is ignored. It is only the second tap that triggers a table cell select again. Any idea what might be causing this or how to work around it? Issue should be easy to reproduce in iOS7 with the above code.
The tableview is in editing state when you delete a particular row. SO you have to turn off the editing state to allow the tableView to go back to the selection mode. Change your code to this -
- (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];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With