Tag: nsfetchedresults

NSFetchedResultsController:在后台线程中获取

我有一个或多或less的基本UITableViewController NSFetchedResultsController 。 UITableViewController被推到navigationController's堆栈上。 但是推animation并不stream畅,因为NSFetchedResultsController的获取是在主线程上执行的,因此阻塞了UI。 我的问题是:如何在后台线程中执行NSFetchedResultsController的获取以保持animation的平滑? NSFetchedResultsController和委托方法如下所示: – (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) { return _fetchedResultsController; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. NSEntityDescription *entity = [NSEntityDescription entityForName:@"GPGrade" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; // Set the batch size to a suitable number. [fetchRequest setFetchBatchSize:20]; //Set predicate NSPredicate *predicate […]

iOS UITableView部分与fetchedResultsController混淆

我只有一个部分在一个表格视图中显示一个实体。 该实体有两个属性, workoutName和trainingLevel 。 两者都是stringtypes。 训练级别由三种types组成:1,2,3(trainingLevel =(整数16或stringtypes,哪一个是理想的?)我想将表格分成三个部分,每个部分包含相应训练级别的条目。 我该怎么做呢? 我目前使用的代码如下: – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return self.workoutType.workouts.count; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView […]

NSFetchedResultsController不会调用controllerDidChangeContent:更新到未获取的NSManagedObject

我填充并save:一个初始的NSManagedObjectContext 用一个不同的NSManagedObjectContext设置一个NSManagedObjectContext ,它过滤一个boolean “show”属性。 最后在另一个NSManagedObjectContext上更新“show”并save: 。 我期望这应该会导致我的NSFetchedResultsController调用NSFetchedResultsControllerDelegate的controllerDidChangeContent: NSFetchedResultsControllerDelegate 我从来没有接到这个电话。 具有谓词的NSFetchedResultsController忽略从不同的NSManagedObjectContext合并的更改中 接受的答案,表明除了controllerDidChangeContent: ,我应该得到一个NSManagedObjectContextObjectsDidChangeNotification ,但是我也没有收到。 一个完整的代码示例包含在下面和github上 。 我已经向苹果提交了一个雷达 。 @interface HJBFoo : NSManagedObject @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSNumber *show; @end @interface HJBAppDelegate () <NSFetchedResultsControllerDelegate> @property (nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator; @property (nonatomic, strong) NSManagedObjectContext *initialManagedObjectContext; @property (nonatomic, strong) NSManagedObjectContext *fetchedResultsControllerManagedObjectContext; @property (nonatomic, strong) NSFetchedResultsController […]

核心数据嵌套托pipe对象上下文和频繁死锁/冻结

我有一个问题,这个人在这里描述的问题几乎相同,但它没有得到回答: http://www.cocoabuilder.com/archive/cocoa/312683-core-data-nested-managed-object-contexts-and-frequent-deadlocks.html#312683 这是问题: 我有一个使用NSPrivateQueueConcurrencyType和一个持久性存储协调器集的父MOC设置,它有一个带有NSMainQueueConcurrencyType的子MOC设置。 这个想法大部分是长时间的努力和保存,可以在私有MOC上完成,使主线程免于阻塞UI。 不幸的是,我似乎遇到了一些导致死锁的情况。 如果孩子MOC(在主线程上)正在使用NSFetchedResultsController执行一个提取操作,父上下文将被发送一个-executeFetchRequest:它可以创build一个死锁。 这两个操作都是在performBlock的上下文中完成的:对于它们各自的MOC,尽pipe文档似乎表明在主线程上使用主线程并发typesMOC而没有执行块:没问题。 看来专用队列正在等待主线程上的子上下文已经locking的PSC锁。 看起来,子上下文(同时持有PSC锁)正试图dispatch_sync到父上下文,因此它们都在等待对方。 是PriveQueue – > MainQueue支持的configuration? 似乎大多数人仍然在主线程上有父上下文。 主线程如下所示: > #0 0x960f6c5e in semaphore_wait_trap () > #1 0x04956bb5 in _dispatch_thread_semaphore_wait () > #2 0x04955c8f in _dispatch_barrier_sync_f_slow () > #3 0x04955dea in dispatch_barrier_sync_f () > #4 0x01797de5 in _perform () > #5 0x01798547 in -[NSManagedObjectContext(_NestedContextSupport) newValuesForObjectWithID:withContext:error:] () > #6 […]