Ios 核心数据-重新排序TableView赢得';救不了
你好, 我有以下代码来设置tableView的重新排序Ios 核心数据-重新排序TableView赢得';救不了,ios,uitableview,core-data,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 m
#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];
}
在它出现在我看来之前
我是否需要为表视图的重新排序设置类似的内容以进行保存?
数据从核心数据数据库获取。重新加载数据时,是否使用从核心数据实体获取的结果重新填充该数组?如果是这样,您对阵列所做的更改(我假设它是电视的数据源)将被吹走。如果您希望这些更改保持不变,则需要以某种方式更新模型,以确保数组的重新填充会导致按您需要的方式对数组进行索引。为了保持对象的顺序,恐怕您需要将该的属性添加到数据模型中。只需使用
int
/[NSNumber]
并在移动表视图行时在循环中重新计算它们。删除视图行时,您可能还需要重新计算索引等。
[self.mainTableView setEditing:YES animated:YES];