gpt4 book ai didi

ios - NSFetchedResultsController 调用 didChangeObject 删除而不是更新

转载 作者:IT王子 更新时间:2023-10-29 05:12:38 24 4
gpt4 key购买 nike

这是代码,我通过 Magical Record 保存模型:

MagicalRecord.saveWithBlock({ (localContext) -> Void in
var localNotification = CDNotification.MR_findFirstByAttribute("notificationID", withValue: notification.notificationID, inContext: localContext) as CDNotification
localNotification.readNumber = NSNumber(bool: true)
})

在调用上面的代码后调用删除而不是更新:

func controller(controller: NSFetchedResultsController, didChangeObject object: AnyObject, atIndexPath indexPath: NSIndexPath, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath) {
switch type {
case NSFetchedResultsChangeType.Insert:
self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
case NSFetchedResultsChangeType.Update:
if let cell = self.tableView.cellForRowAtIndexPath(indexPath){
self.configureCell(cell as TableViewCell, atIndexPath: indexPath, withNotification: object as CDNotification)
}
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
case NSFetchedResultsChangeType.Move:
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
case NSFetchedResultsChangeType.Delete:
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
default:
return
}
}

这只有在我为获取请求设置谓词时才会发生,例如:

fetchRequest.predicate = NSPredicate(format:"user == john")

最佳答案

这里发生的是,您得到的不是您期望的 NSFetchedResultsChangeUpdate 更改事件,而是一个 NSFetchedResultsChangeDelete 后跟 NSFetchedResultsChangeInsert。您还可能会看到 NSFetchedResultsChangeMove 具有与源和目标相同的 indexPath。这是 several beta versions of iOS 9 中的一个已知问题22380191和其他人。

关于ios - NSFetchedResultsController 调用 didChangeObject 删除而不是更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26832627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com