Tag: nsfetchedresultscontroller

带有UICollectionView的NSFetchResultController与索引/单元格有关的更新和删除操作

第一次,我使用UICollectionView,我有一些困难。 特别是更新和删除单元格(将重点放在这里删除,希望NSFetchResultController ),从NSFetchResultController数据。 我在界面生成器中创build了一个自定义单元格,作为这样一个故事板的一部分: 我有一个自定义的UICollectionViewCell子类具有以下属性: @property (strong, nonatomic) IBOutlet UIButton *deleteButton; @property (strong, nonatomic) IBOutlet UITextField *textField; @property (strong, nonatomic) IBOutlet UIView *containerView; @property (strong, nonatomic) IBOutlet UIView *textFieldContainer; 在IB中,我将单元类设置为自定义类,将元素连接到自定义类的属性,并将标识设置为Cell 。 在我的集合视图视图控制器中,我设置了集合视图和fetchResultController以及相关的方法,如下所示: – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return [[self.fetchedResultsController sections] count]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section]; return [sectionInfo numberOfObjects]; […]

NSFetchedResultsController按名字或姓氏sorting

我基本上是试图用名字和姓氏,或者名字或姓氏来实现NSSortDescriptor? 但是有一个NSFetchedResultsController。 我正在阅读地址簿中的logging,并希望像地址簿一样显示它们。 logging将根据姓氏的第一个字母分类。 如果没有姓,则按名字sorting,如果没有名字,则按公司sorting。 目前我有 – (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) { return _fetchedResultsController; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // read the contact list NSEntityDescription *entity = [Contact MR_entityDescriptionInContext:[NSManagedObjectContext MR_defaultContext]]; [fetchRequest setEntity:entity]; // sort the results by last name then by first name NSSortDescriptor *sort1 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES […]

如何使用NSFetchedResultsController在date之后生成节

我正在呈现一个托pipe对象的列表,其中每个都有timeStamp属性。 我想按照时间顺序使用timeStamp属性对我进行sorting,我使用NSSortDescriptor进行sorting。 但是我也想根据整个date生成部分(每天一个部分) 以下将给我一个基于第二差异的部分太多部分: NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"timeStamp" cacheName:@"PatientDetailViewCache"]; 有没有一种方法来生成部分从NSFetchedResultsController格式化如yy-MM-dd timeStamp属性? 谢谢你的帮助 基督教

EXC_BAD_ACCESS和NSFetchedResultsController

试图追踪这个错误,当我有NSZombieEnabled 。 当获取的结果控制器尝试执行提取时,我得到一个EXC_BAD_ACCESS。 debugging器说: -[CFNumber retain]: message sent to deallocated instance 0x6e88d10 Backtrace说: #0 0x014bbe1e in ___forwarding___ () #1 0x014bbce2 in __forwarding_prep_0___ () #2 0x0145c490 in CFRetain () #3 0x0147929a in CFNumberCreate () #4 0x00b221ed in -[NSPlaceholderNumber initWithShort:] () #5 0x00b2216a in +[NSNumber numberWithShort:] () #6 0x010a549e in snapshot_get_value_as_object () #7 0x010a2a41 in _sharedIMPL_pvfk_core () […]

NSFetchedResultsController的节名称与pipe理对象值不匹配

我正在使用一个NSFetchedResultsController来填充一个UITableView结果从一个中等规模的核心数据存储约1500个实体。 结果控制器是相当标准的 – 对于这种设置,潜在错误的一些“热点”是不正确的。 在同一个(主)线程上创build的托pipe对象上下文与其上的一样 没有使用caching(因为sorting频繁变化) sectionNameKeyPath用于将结果拆分成多个部分 然而,我的部分结果非常奇怪。 例如,考虑用于设置节标题视图的标题的方法: – (NSString *)titleForHeaderInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [[self.resultsController sections] objectAtIndex:section]; return [sectionInfo name]; // <——- Stopped at breakpoint here } 我已经停在指定的行使用断点,并使用GDB,检查以下内容: (gdb) po [[self resultsController] sectionNameKeyPath] reviewDateString (gdb) print section $11 = 1 (gdb) print (int) [sectionInfo numberOfObjects] $12 = 4 (gdb) po [sectionInfo name] […]

从UICollectionView的viewForSupplementaryElementOfKind获取NSFetchedResultsController节对象

我有一个名为Location的数据模型。 我在UICollectionViewController使用这些作为我的部分标题。 每个location都可以显示这些部分内的items 。 我想在viewForSupplementaryElementOfKind自定义我的部分标题。 但我不知道如何从这个方法recive正确的Location对象。 我曾尝试过这样的事情: -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections] [indexPath.section]; Item *item = sectionInfo.objects[0]; Location *location = item.location; SectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SectionHeader" forIndexPath:indexPath]; headerView.label.text = location.name; […] 但我不断收到: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 […]

集合函数上的iOS FetchRequest:如何包含挂起的更改?

我终于至less缩小了这个问题。 我正在计算一些支出的总和函数(在这个例子中是总和)。 如果我改变了一些支出,这个聚集提取不会立即刷新,而只是在一段时间之后(可能在更改被保存到数据库之后)。 我在文档中find了这个部分: – (void)setIncludesPendingChanges:(BOOL)yesNo 根据文件 结果typesNSDictionaryResultType不支持YES值,包括计算聚合结果(如max和min)。 对于字典,从读取中返回的数组反映了持久性存储中的当前状态,并且不考虑上下文中的任何挂起的更改,插入或删除。 如果您需要为最大和最小等简单聚合考虑待处理的更改,则可以改为使用正常的获取请求,按照所需的属性进行sorting,获取限制为1。 好的,我怎么能仍然包括未决的变化? 我正在使用NSFetchedResultsController来显示我的数据。 这里是我的聚合函数: – (NSNumber *)getExpendituresAmountForCostPeriod:(CostPeriod)costPeriod { NSLog(@"getExpenditures_Start"); NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Expenditures"]; [fetchRequest setResultType:NSDictionaryResultType]; NSDate *startDate = [NSDate startDateForCostPeriod:[self getBiggestCostPeriod]]; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"forSpendingCategory = %@ AND date >= %@", self, startDate]; //Define what we want NSExpression *keyPathExpression = [NSExpression expressionForKeyPath: @"amount"]; NSExpression *sumExpression […]

NSFetchedResultsController不能使用瞬态属性

使用Xcode8.3在Swift 3中正常工作 我有一个项目正在进行,其中有保存消息的核心数据。 它按照时间对邮件进行分类,并按照date分类。 就是这样: let request = NSFetchRequest(entityName: "Message") let sortDiscriptor = NSSortDescriptor(key: "time", ascending: true) request.sortDescriptors = [sortDiscriptor] fetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: mainThreadMOC, sectionNameKeyPath: "sectionTitle", cacheName: nil) fetchedResultsController.delegate = self do { try fetchedResultsController.performFetch() } catch { fatalError("Failed to initialize FetchedResultsController: \(error)") } 这是暂时的财产: var sectionTitle: String? { //this is **transient** property […]

在UIManagedDocuments获取新数据后,NSFetchedResultsController不会更新TableView

我正在使用一个NSFetchedResultsController与在后台线程中得到更新的UIManagedDocument组合。 我已经完全按照本教程中的描述设置了NSFetchedResultsController: 如何使用NSFetchedResultsController 我已经把委托_fetchedResultsController.delegate = self和我的视图控制器的协议设置_fetchedResultsController.delegate = self 。 我的代码在启动后加载数据时工作正常。 但是, NSFetchedResultsController 不会更新TableView,只要它已经处理并将数据保存在后台线程中。 特别是,NSFetchedResultsController的委托方法-controllerWillChangeContent:controller等永远不会被调用。 我已经仔细检查SQLite数据库是否包含正确的数据。 这是我如何处理和保存在视图控制器中的数据: [backgroundContext performBlock:^{ [company parseAttributesFrom:xmlStr inManagedObjectContext:backgroundContext]; //self.managedDocument.managedObjectContext NSError *error = nil; [backgroundContext save:&error]; if (error) NSLog(@"error: %@",error.localizedDescription); [self.managedDocument.managedObjectContext performBlock:^{ NSError *error = nil; [self.managedDocument.managedObjectContext save:&error]; if (error) NSLog(@"error: %@",error.localizedDescription); }]; [self.managedDocument saveToURL:self.managedDocument.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL]; [self.managedDocument updateChangeCount:UIDocumentChangeDone]; }]; 当底层数据发生变化时,如何让NSFetchedResultsController自动更新TableView? 感谢您的帮助!

格式sectionNameKeyPath NSFetchedResultsController – Swift

我试图格式化我的sectionNameKeyPath我的核心数据获取使用存储的NSDate属性。 它是完全正常工作,并根据NSDate将logging分为不同的部分,但我不知道如何格式化以dd-mm-yyyy显示。 我知道如何格式化NSDate使用: let date = NSDate(timeIntervalSince1970:myTimeInterval) let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy" 我目前的获取请求使用核心数据属性sectionDate作为sectionDate的部分 取 let fetchRequest = NSFetchRequest(entityName: "VisitDetails") let primarySortDescriptor = NSSortDescriptor(key: "dateDue", ascending: false) let sortDescriptors = [primarySortDescriptor] fetchRequest.sortDescriptors = sortDescriptors let frc = NSFetchedResultsController( fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext!, sectionNameKeyPath: "dateSections", cacheName: nil) frc.delegate = self 所以为了澄清我想格式化输出和sorting只是dd-MM-yyy。 目前看起来像 我认为一个黑客正在创build一个额外的属性,并input一个格式化的string,然后用这个来区分结果?