Tableviews: fix edition/suppression of items in table views with checkboxes

This commit is contained in:
Gautier Pelloux-Prayer 2015-10-22 12:27:59 +02:00
parent 9e600af7d7
commit ef90322429
2 changed files with 13 additions and 3 deletions

View file

@ -123,12 +123,16 @@
logs = ms_list_next(logs);
}
[self computeSections];
[super loadData];
}
- (void)computeSections {
NSArray *unsortedDays = [self.sections allKeys];
self.sortedDays = [unsortedDays sortedArrayUsingComparator:^NSComparisonResult(NSDate *d1, NSDate *d2) {
return ![d1 compare:d2]; // reverse order
}];
[super loadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
@ -207,6 +211,9 @@
[[_sections objectForKey:_sortedDays[indexPath.section]] removeObject:log];
if (((NSArray *)[_sections objectForKey:_sortedDays[indexPath.section]]).count == 0) {
[_sections removeObjectForKey:_sortedDays[indexPath.section]];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationFade];
[self computeSections];
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]

View file

@ -75,6 +75,7 @@
cell.accessoryType = UITableViewCellAccessoryNone;
}
_deleteButton.enabled = (_selectedItems.count != 0);
_editButton.enabled = YES;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
@ -101,12 +102,14 @@
[_selectedItems sortUsingComparator:^(NSIndexPath *obj1, NSIndexPath *obj2) {
return [obj2 compare:obj1];
}];
for (NSIndexPath *indexPath in _selectedItems) {
NSArray *copy = [[NSArray alloc] initWithArray:_selectedItems];
for (NSIndexPath *indexPath in copy) {
[self tableView:self.tableView
commitEditingStyle:UITableViewCellEditingStyleDelete
forRowAtIndexPath:indexPath];
}
[_selectedItems removeAllObjects];
[self setEditing:NO animated:YES];
}
- (void)onSelectionToggle:(id)sender {