Я столкнулся с очень похожим вопросом здесь: https://stackoverflow.com/questions/3160796/inserting-row-to-end-of-table-with-uitableviewrowanimationbottom-doesnt-animate,, хотя ответы не были даны.Его код также немного отличался от моего.
У меня есть чрезвычайно простой пример, построенный из шаблона приложения Navigation.
NSMutableArray *items;
- (void)viewDidLoad {
[super viewDidLoad];
items = [[NSMutableArray array] retain];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem)] autorelease];
}
- (void)addItem{
[items insertObject:@"new" atIndex:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [items objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[items removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
}
}
Проблема заключается в том, что когда я либо вставляю, либо удаляюсамая последняя строка в таблице, анимация вообще не работает;строка просто появляется или исчезает мгновенно.Это происходит только с UITableViewRowAnimationBottom, но именно эта анимация имеет больше смысла для создания или удаления ячеек таблицы таким способом.Это ошибка в структуре Apple?Или это делается специально?Имеет ли смысл добавить дополнительную ячейку к счетчику, а затем настроить эту ячейку так, чтобы она выглядела так, будто ее вообще нет, просто чтобы обойти это поведение?