我希望我的 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;
}