Tag: nsfetchedresults

当插入/删除顶部/底部单元格时,更新旧/新顶部/底部单元格的backgroundView

这是NSFetchedResultsControllerDelegate文档中给出的模板代码: – (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.tableView beginUpdates]; } – (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { switch(type) { case NSFetchedResultsChangeInsert: [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; } } – (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { UITableView *tableView = self.tableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] […]

奇怪的父/子NSManagedObjectContext现象

我已经创build了两个这样的背景: // create writer MOC _privateWriterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [_privateWriterContext setPersistentStoreCoordinator:_persistentStoreCoordinator]; // create main thread MOC _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; _managedObjectContext.parentContext = _privateWriterContext; 我有一个NSFetchResultedController用_managedObjectContext启动。 我知道这很奇怪,但我正在向父级添加一条logging到_privateWriterContext ,我正在saving它。 令人惊讶的是,儿童情况,所以FRC得到这个事件的通知。 为什么? 我没有reset孩子,或其他任何东西。 我以为他们是独立的实体,只要孩子的情况下不会得救。 在@pteofil文章中,我发现这一行: 当一个环境发生了变化,但没有得到保存时,它的所有后代都可以看到,但是不会看到它的祖先。 它被推送到持久性存储(通过持久性商店协调器),并且对连接到商店的所有上下文都可见。

NSFetchedResultsController节号是0

我有以下层次的实体 在我的TableViewController我有以下代码: private lazy var fetchedResultsController: NSFetchedResultsController = { let fetchRequest = NSFetchRequest(entityName: "Worker") let workerTypeSortDescriptor = NSSortDescriptor(key: "workerType", ascending: true) let firstNameSortDescriptor = NSSortDescriptor(key: "firstName", ascending: true) fetchRequest.sortDescriptors = [workerTypeSortDescriptor, firstNameSortDescriptor] guard let stack = CoreDataStackSingleton.sharedInstance.coreDataStack else {return NSFetchedResultsController()} let frc = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: stack.mainQueueContext, sectionNameKeyPath: "workerType", cacheName: nil) frc.delegate = self return […]

在后台moc中删除对象然后在主moc中刷新它导致NSFetchedResultsController更新崩溃

我遇到了一个我无法理解的NSObjectInaccessibleException : *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x8c40040 <x-coredata://85B02C1C-1FFC-4CBF-B7AC-EEA259115427/Event/p6>'' *** First throw call stack: ( 0 CoreFoundation 0x01aa15e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x018248b6 objc_exception_throw + 44 2 CoreData 0x0025733b _PFFaultHandlerLookupRow + 2715 3 CoreData 0x00256897 -[NSFaultHandler fulfillFault:withContext:forIndex:] + 39 4 CoreData 0x00256473 _PF_FulfillDeferredFault […]

使用NSSortDescriptor将“nil”值保留在列表的底部

我正在sortingNSFetchedResultController数据。 我需要按名字sorting数据。 但是,有一些没有名字的条目。 我需要“无名”对象出现在列表的底部,而不是顶部。 使用当前的代码,当我按名sorting列表时,“无名”单元格放在顶部。 NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Contacts"]; request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES]]; _FRC = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:MOC sectionNameKeyPath:nil cacheName:nil]; _FRC.delegate = self;

NSFetchedResultsController调用didChangeObject删除而不是更新

这是代码,我通过魔法logging保存模型: 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, […]

NSFetchedResultsController尝试限制显示的logging数

当创build一个NSFetchedResultsController传递给我的NSFetchedResultsController时,我将fetchLimit属性设置为3。 现在最初这似乎工作正常。 我可以以任何方式修改前三个返回的对象,改变它们的顺序,并且全部重新正确。 当我改变一个最初落在前三个物体之外的物体时,会出现这个问题,现在将其引入前三个物体,或者只是添加一个新的物体,使其出现在前三个物体中。 我期望发生的事情:插入的物体将其余部分向下推,一个从底部落下。 究竟发生了什么:插入的对象将其余部分向下推, logging数增长到4 ?! 任何人都可以解释这个,或者我应该如何处理这个?

带有NSFetchedResultsController的表移动添加部分的行

我有UITableView与NSFetchedResultsController NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:[self dataFetchRequest] managedObjectContext:[MLCoreDataService sharedInstance].managedObjectContext sectionNameKeyPath:@"checked" cacheName:nil]; aFetchedResultsController.delegate = self; 我已经实施 – (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { UITableView *tableView = self.tableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeUpdate: [(MLItemTableViewCell*)[tableView cellForRowAtIndexPath:indexPath] setItem:anObject]; break; case NSFetchedResultsChangeMove: [tableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath]; […]

合并后台线程更新后,NSFetchedResultsController不会触发委托方法

我有一个NSFetchedResultsController和一些操作,通过NSOperationQueue在单独的线程上插入和更新托pipe对象。 FRC看起来像这样,请注意,我已将caching设置为零: [NSFetchedResultsController deleteCacheWithName:nil]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil]; 每个线程操作都有自己的托pipe对象上下文,并在每次保存更改时触发mergeChangesFromContextDidSaveNotification到主MOC。 我用来合并上下文的代码如下所示: – (void)mergeContextChanges:(NSNotification *)notification { NSManagedObjectContext *context = [fetchedResultsController managedObjectContext]; if([NSThread isMainThread] == NO) { [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO]; return; } NSSet *updated = [[notification userInfo] objectForKey:NSUpdatedObjectsKey]; for(NSManagedObject *thing in updated) { NSLog(@"Background thread updated %@", [thing description]); } for(NSManagedObject *thing […]

使用“to many”关系从NSFetchedResultsController派生UITableView节

我的核心数据模型如下所示: article <—>> category 是否可以使用NSFetchedResultsController来产生一个看起来像这样的UITableView? Category 1 – Article A – Article B – Article C Category 2 – Article A – Article D – Article E – Article F Category 3 – Article B – Article C 具体而言,我对每个UITableView部分具有唯一标题(例如“类别1”,“类别2”)的(边缘?)情况感兴趣,但同一对象可以存在于多个部分中(例如,在类别1和类别2中)。 我search了苹果的Core Data文档,花了两天的时间仔细阅读这些问题,但是,唉,连这个也不知道是否可行,更别提怎么实现了。 感谢任何帮助或指向以前回答的问题。 我当然找不到它。