Я бы хотел, чтобы мой UITableView вел себя как таблица в редакторе контактов, то есть пользователь должен нажать "Изменить", а строка "добавить новую категорию" должна появиться внизу каждого раздела.
Я использую приведенный ниже код для этого, но проблема в том, что плавный переход не происходит, как в "Контакты". Вместо этого появляется новая строка. Как я могу получить анимацию?
Также, как мне реагировать на клики по строке "добавить новую категорию"? Строка не может быть нажата в моей текущей реализации.
Нужно ли перезагружать данные, когда пользователь начинает редактирование? Я делаю это, потому что иначе строки вставки никогда не рисуются.
Спасибо.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)_tableView numberOfRowsInSection:(NSInteger)section {
// ...
if( self.tableView.editing )
return 1 + rowCount;
}
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// .....
NSArray* items = ...;
if( indexPath.row >= [items count] ) {
cell.textLabel.text = @"add new category";
}
// ...
return cell;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray* items = ...;
if( indexPath.row == [items count] )
return UITableViewCellEditingStyleInsert;
return UITableViewCellEditingStyleDelete;
}