1

我正在尝试找到一个代码示例,该示例显示如何处理 tableView 中的移动/重新排列单元格。

为了删除核心数据,我使用下面编写的代码

- (void)tableView:(UITableView *)aTableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

if (editingStyle == UITableViewCellEditingStyleDelete)

{

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"MyBase"
                                                         inManagedObjectContext:self.objectContext];
    [fetchRequest setEntity:entityDescription];


    NSArray *empArray=[self.objectContext executeFetchRequest:fetchRequest error:nil];

    if ([empArray count] > 0){
        Moneybox *employee = [empArray objectAtIndex:indexPath.row];
        [self.objectContext deleteObject:employee];
        [self.objectContext save:nil];

    }

    [self buscarContactoExistente];
    [myTable reloadData];

}

}

我该怎么做

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 

风格相同?

4

1 回答 1

1
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
      toIndexPath:(NSIndexPath *)toIndexPath 
{
    Moneybox *employee = [empArray objectAtIndex:fromIndexPath.row];
    [empArray removeObject: employee];
    [empArray insertObject:employee atIndex:toIndexPath.row];
}
于 2013-10-11T10:24:12.083 回答