与 iCloud 连接的 iOS 应用程序崩溃

标签 ios core-data ios5 nsfetchedresultscontroller icloud

我的应用程序只使用一个 managedObjectContext 并设置为与 iCloud 同步核心数据更改,我正在使用 NSFetchedResultsController 为我的 UITableView< 获取数据。当我尝试编辑(重新排序)表格单元格时出现问题。

想象一下这个场景:

我执行[tableView setEditing:YES animated:YES];
我将手指按住一行,然后开始在 tableView 周围移动它(重新排序)。与此同时,我在 mac 应用程序中删除了一行,并保存更改。

iOS 应用开始了解新变化,我的 fetchedResultsController 尝试调用 [tableView beginUpdates] ... 并从 tableView< 中删除该行 正在编辑。

我不知道它是否应该这样工作,但它崩溃了。

你会如何尝试解决这个问题?

日志:

***[3758:707] asynchronously added persistent store!
***[3758:707] numberOfRowsInSection:3
***[3758:707] numberOfRowsInSection:2
***[3758:707] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1912.3/UITableView.m:1046
***[3758:707] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)
***[3758:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]'

前两个日志位于 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 方法中并记录我返回的内容。发现第一次返回3,第二次返回2!

编辑:现在我在想......它应该这样工作,还是我必须找到另一种方法来实现它?拖动单元格并调用 [tableView moveRowAtIndexPath:toIndexPath:] 时会发生什么? ?

最佳答案

您的崩溃说明您启动了一个 -beginUpdates block ,删除了一行,然后调用了 -endUpdates,但是当 tableview 向其数据源询问该部分中的行,它在预期 2 时返回 3。听起来您没有正确更新数据源。

关于与 iCloud 连接的 iOS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973962/

相关文章:

objective-c - 如何在 objective-c ios5 中设置默认删除按钮的样式?

ios5 - 错误 :(null) is not a valid containment controller key path?

ios - 监控 CBPeripheral 状态变化

ios - 需要CFReadStream block ,直到未填充缓冲区大小

objective-c - 指定核心数据属性的有效值

iphone - 用新的 iOS 5 Accounts.framework 替换用户名/密码

iphone - AVPlayer 的时间轴进度条

ios - 如何在 ios 中按返回键不关闭键盘

ios - NSSortDescriptor 将字符串字段排序为数字,比较器 block 不起作用

ios - 在 iOS 上存储对象 - 最佳解决方案?