iOS usuwa wiersz widoku tabeli
Miałem swoją aplikację działającą w systemie iOS 6. Wraz z aktualizacją przestałem być w stanie usuwać wiersze z mojegoUITableView
.
Mam guzik w mojej prototypowej komórce.
Oto funkcja przycisku:
- (IBAction)deleteCell:(id)sender {
UIButton *btn = (UIButton*) sender;
UITableViewCell *cell = (UITableViewCell*) btn.superview.superview;
NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
if([names count] > 9) {
int index = indexPath.row;
[names removeObjectAtIndex:index];
[photos removeObjectAtIndex:index];
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
}
}
Problem polega na tym, że zmienna indeksu ma zawsze wartość 0.
Spróbowałem innego rozwiązania:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
int index = indexPath.row;
[names removeObjectAtIndex:index];
[photos removeObjectAtIndex:index];
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
}
}
To rozwiązanie też nie działa. Nic się nie dzieje, kiedy macham w prawo.