繁体   English   中英

核心数据-重新排列TableView不会保存

[英]Core Data - Reordering TableView won't save

你好,

我有以下代码来设置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];

才出现在我看来。

我需要对表视图的重新排序进行设置以保存它吗?

从核心数据数据库中获取数据。

恐怕为了保持对象的顺序,恐怕您需要为该数据模型 添加一个属性 只需使用int / [NSNumber]并在移动表视图行时循环重新计算它们即可。

重新加载数据时,是否要使用从Core Data实体中获取的结果重新填充该数组? 如果是这样,您对阵列所做的更改(我认为是电视的数据源)将被吹走。 如果要保留这些更改,则需要以某种方式更新模型,以确保重新填充数组会导致按所需方式对数组进行索引。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM