我在我的iPhone应用程序中使用CoreData,但CoreData没有提供允许您重新排序记录的自动方式.我想使用另一列来存储订单信息,但使用连续的数字来排序索引有一个问题.如果我处理大量数据,重新排序记录可能涉及更新订单信息上的大量记录(这有点像改变数组元素的顺序)
实施有效订购方案的最佳方法是什么?
可能重复:
如何实现CoreData记录的重新排序?
我正在尝试找到一个代码示例,该示例演示如何在单元格使用fetchedResultsController(即与Core Data结合使用)时处理tableView中的移动/重新排列单元格.我正在获取moveRowAtIndexPath:调用我的数据源,但我无法找到正确的黑魔法组合,以使表/数据正确识别更改.
例如,当我将第0行移动到第2行然后放开时,它"看起来"正确.然后我点击"完成".向上滑动以填充第0行的行(1)仍然具有编辑模式外观(减去和移动图标),而下面的其他行滑回到正常外观.如果我然后向下滚动,因为第2行(原来是0,记得?)接近顶部,它会完全消失.
WTF.我是否需要以某种方式使fetchedResultsController无效?每当我将它设置为零时,我都会崩溃.我应该发布它吗?我在杂草里吗?
这是我目前在那里得到的......
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
/*
Update the links data in response to the move.
Update the display order indexes within the range of the move.
*/
if (fromIndexPath.section == toIndexPath.section) {
NSInteger start = fromIndexPath.row;
NSInteger end = toIndexPath.row;
NSInteger i = 0;
if (toIndexPath.row < start)
start = toIndexPath.row;
if (fromIndexPath.row > end)
end = fromIndexPath.row;
for (i = start; i <= end; …
Run Code Online (Sandbox Code Playgroud) 有没有人有使用NSOrderedSet在UITableView中进行排序的示例代码?
曾阅读过很多关于重新排序的文章,但仍然不明白如何在iOS5中做到这一点.