vbu*_*vic 20 core-data nsfetchedresultscontroller ios magicalrecord swift
这是代码,我通过魔法记录保存模型:
MagicalRecord.saveWithBlock({ (localContext) -> Void in
var localNotification = CDNotification.MR_findFirstByAttribute("notificationID", withValue: notification.notificationID, inContext: localContext) as CDNotification
localNotification.readNumber = NSNumber(bool: true)
})
Run Code Online (Sandbox Code Playgroud)
调用上面的代码后,调用Delete而不是update:
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
}
}
Run Code Online (Sandbox Code Playgroud)
只有在我为获取请求设置谓词时才会发生这种情况,例如:
fetchRequest.predicate = NSPredicate(format:"user == john")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1362 次 |
| 最近记录: |