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;
}