次のコードで試しました。それは正常に動作します。しかし、いくつかのことを達成する方法がわかりません。
同じ行の削除コントロールの代わりに「削除」ボタンをクリックしたときに挿入コントロールを追加するにはどうすればよいですか?
「セクション 3」を「セクション 1」と「セクション 2」の間に移動した場合、3 つのセクションすべてを削除コントロールで更新するにはどうすればよいですか?
これまでのところ、以下のコードを使用して次の出力を得ています。
-(void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Handle things when deletion control clicked!
//[sectionArray removeObjectAtIndex:indexPath.row];
//[self.tableView reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
//Handle things when insertion control clicked!
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
// No editing style if not editing or the index path is nil.
if (isEditMode == NO || !indexPath) return UITableViewCellEditingStyleNone;
if (indexPath.row == 1){
return UITableViewCellEditingStyleDelete;
}else if (indexPath.row == 2){
return UITableViewCellEditingStyleInsert;
}else if (indexPath.row == 3){
return UITableViewCellEditingStyleInsert;
}else {
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
NSString *item = [sectionArray objectAtIndex:fromIndexPath.row];
[sectionArray removeObject:item];
[sectionArray insertObject:item atIndex:toIndexPath.row];
NSLog(@"%@", sectionArray);
}