核心数据 - 重新排序TableView将无法保存

时间:2012-05-19 22:12:16

标签: ios uitableview core-data

您好,

我有以下代码来设置tableView的重新排序。

#pragma mark Row reordering
// Determine whether a given row is eligible for reordering or not.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
// Process the row move. This means updating the data model to <span id="IL_AD6" class="IL_AD">correct</span> the item indices.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
  toIndexPath:(NSIndexPath *)toIndexPath {
NSString *item = [arr objectAtIndex:fromIndexPath.row];
[arr removeObject:item];
[arr insertObject:item atIndex:toIndexPath.row];


}

但是当我重新加载TableView时(注意不是TableViewController)顺序设置回到我改变之前的状态。

现在,当我为此视图设置编辑(删除按钮)时,我不得不添加以下行:

[self.mainTableView setEditing:YES animated:YES];

在我看来之前。

我需要设置一个类似的事情来重新排序表格视图以便保存吗?

从Core Data数据库中提取数据。

2 个答案:

答案 0 :(得分:1)

为了坚持对象的顺序我害怕你需要为添加属性到你的数据模型。只需使用int / [NSNumber],并在移动表格视图行时在循环中重新计算它们。

答案 1 :(得分:0)

重新加载数据时,是否使用Core Data实体的提取结果重新填充该数组?如果是这样,您对阵列所做的更改(我假设是电视的数据源)将被吹走。如果您希望这些更改坚持下去,您需要以某种方式更新模型,以确保数组的重新填充导致数组按您所需的方式编制索引。

相关问题