我已经尝试过以下代码。它工作正常。但我想不出如何实现几件事。
当我单击“删除”按钮而不是同一行上的删除控件时,如何添加插入控件?
如果我将“第 3 节”移动到“第 1 节”和“第 2 节”之间,如何更新所有三个包含删除控制的节?
到目前为止,我已经使用下面的代码得到了以下输出。
-(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);
}