Tag: nsfetchedresultscontroller

NSFetchedResultsController忽略fetchLimit?

我有一个NSFetchedResultsController来更新与核心数据内容的UITableView。 这是非常标准的东西,我相信你们都看过很多次,但是我遇到了一些小问题。 首先这是我的代码: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Article" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; [fetchRequest setFetchLimit:20]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(folder.hidden == NO)"]; [fetchRequest setPredicate:predicate]; NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"sortDate" ascending:NO]; [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort1, nil]]; NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; [fetchRequest release]; controller.delegate = self; self.fetchedResultsController = controller; […]

NSFetchedResultsController更新错误的更新types

请在盲目投票之前查看这些意见。 这不是一个重复的问题。 首先 – 我正在使用MagicalRecord核心数据。 其次 – 我的UICollectionView填充UICollectionView 。 NSPredicate是… NSPredicate *eventPredicate = [NSPredicate predicateWithFormat:@"event = %@", self.event]; NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deleted == NO"]; NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[eventPredicate, deletedPredicate]]; 当我使用Magical Record的saveWithBlock将新项目添加到CoreData时, collectionView正确更新并将更改animation到视图中。 问题是,当我将更改的值删除到@YES … [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) { Photo *photo = [[self photoAtIndexPath:[self.collectionView indexPathForCell:cell]] inContext:localContext]; photo.deleted = @YES; }]; 然后NSFetchedResultsController委托方法触发,除非它触发与更改typesNSFetchedResultsChangeUpdate 。 这不是它应该是。 它应该是NSFetchedResultsChangeDelete作为更改已删除的值应从删除请求中删除它。 […]

NSFetchedResultsController:多个FRC,更新时委派错误

目标:使用FRC,通过startDate (一个NSDate属性)对Section's进行sorting,但是希望Today的Section出现在Upcoming dates Section之前。 我使用瞬态属性sectionIdentifier跟踪了Apple的代码。 苹果的示例代码 。 并首先从这个项目开始: OneFRC 我很快意识到,这可能不可能与一个FRC(我可能是错的)。 接下来,我决定用3 FRCs 刺杀这个 : ThreeFRC 。 TableView sections现在显示在我想要的订单中: 第0部分: Today 第一部分: Upcoming 第二部分: Past 但是,添加数据会触发FRC委托,并且出现以下错误: 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 […]

核心数据不会对已更改的谓词做出反应

这是一个奇怪的问题。 在我的视图控制器SpieleOrtTVC我将展示Spiel实体的一个子集。 每次调用视图控制器时,都应该根据用户在视图控制器中的select来显示不同的子集。 这对于每次第一次调用视图控制器都很有效。 取决于用户的select,抓取文件被移交给新的视图控制器,并正确地到达那里,正如NSLogcertificate的那样。 显示的结果和数据也是如此。 但是当视图控制器被第二次或第三次调用时,那么正确的获取条件也会被传递给视图控制器,但是这个获取结果对应于之前执行的获取。 这是代码。 SpieleOrtTVC被称为地图标注。 所选对象的名称恰好在注释标题中,被移交给新近实现的SpieleOrtTVC。 调用视图控制器与地图: – (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control { SpieleOrtTVC *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:STORYBOARD_ID_SPIELE_ORT]; MKPointAnnotation *theAnnotation = (MKPointAnnotation *) pin.annotation; NSLog(@"the Annotation %@",theAnnotation.title); detailViewController.ortName = theAnnotation.title; detailViewController.stadionName = theAnnotation.subtitle; [self presentViewController:detailViewController animated:YES completion:nil]; } SpieleOrteTVC.h: @property (strong, nonatomic) NSString *ortName; @property (strong, nonatomic) NSString *stadionName; […]

核心数据 – 如何获取具有最大值属性的实体

我有一个实体Person与财产personId (personId是唯一的) 我怎样才能获取最大personId的人? (我想把这个人本身取而不是财产的价值)

NSFetchedResultsController与UILocalizedIndexedCollat​​ion

我正在尝试使用混合语言数据的FRC,并希望有一个部分索引。 从文档看来,您应该能够覆盖FRC – (NSString *)sectionIndexTitleForSectionName:(NSString *)sectionName – (NSArray *)sectionIndexTitles 然后使用UILocalizedIndexedCollat​​ion来获得本地化的索引和部分。 但可悲的是,这是行不通的,不是什么打算使用:( 有没有人能够使用UILocalizedIndexedCollat​​ion FRC或我们被迫使用示例UITableView + UILocalizedIndexedCollat​​ion示例中提到的手动sorting方法(示例代码包括我得到这个工作)。 使用以下属性 @property (nonatomic, assign) UILocalizedIndexedCollation *collation; @property (nonatomic, assign) NSMutableArray *collatedSections; 和代码: – (UILocalizedIndexedCollation *)collation { if(collation == nil) { collation = [UILocalizedIndexedCollation currentCollation]; } return collation; } – (NSArray *)collatedSections { if(_collatedSections == nil) { int sectionTitlesCount = [[self.collation […]

更改托pipe对象属性不会触发NSFetchedResultsController更新表视图

我有一个带谓词的fetchedResultsController ,其中“isOpen == YES” 当调用closeCurrentClockSet时 ,我将该属性设置为NO 。 因此,它不应该再出现在我的tableView。 由于某种原因,这没有发生。 有人可以帮我解决这个问题吗? -(void)closeCurrentClockSet { NSPredicate * predicate = [NSPredicate predicateWithFormat:@"isOpen == YES"]; NSArray *fetchedObjects = [self fetchRequestForEntity:@"ClockSet" withPredicate:predicate inManagedObjectContext:[myAppDelegate managedObjectContext]]; ClockSet *currentClockSet = (ClockSet *)fetchedObjects.lastObject; [currentClockSet setIsOpen:[NSNumber numberWithBool:NO]]; } – 我有更多的方法,使用完全相同的方法 ,通过调用自定义的fetchRequestForEntity:withPredicate:inManagedObjectContext方法。 在这些方法中,当更改属性时,tableView会正确更新! 但是上面这一个( closeCurrentClockSet ),不! 我无法弄清楚为什么。 – 我的fetchedResultsController的实现来自Apple的文档。 另外,另一个细节。 如果我发送我的应用程序,背景。 closures它,重新打开,tableView显示更新,因为它应该! 我已经尽力在stackoverflow上遵循先前的问题。 没有运气。 我也NSLogged这个骨头。 该对象正在被正确提取。 这是正确的。 […]

具有谓词的NSFetchedResultsController忽略从不同NSManagedObjectContext合并的更改

我使用NSFetchedResultsController呈现表视图内容,它有一个谓词: [NSPredicate predicateWithFormat:@"visible == %@", [NSNumber numberWithBool:YES]] 在使用单独NSManagedObjectContext后台线程上,我更新了一些实体,并将其visible值从NO更改为YES 。 保存,合并主线程的NSManagedObjectContext更改。 但fetchedObjects不会改变。 另外控制器不会在-controller:didChangeObject:…上调用-controller:didChangeObject:… 如果实体在主线程上以相同的方式更新(我的testing应用程序调用相同的方法),一切都按预期工作。 另外通知的NSUpdatedObjectsKey包含这些对象。 目前唯一的解决scheme是find每个NSUpdatedObjectsKey实体: NSManagedObjectContext *context = … // main thread context [context existingObjectWithID:[object objectID] error:nil] 此问题仅适用于以前与谓词不匹配的更新对象。 我错过了什么明显的?