Tag: nsfetchedresults

为什么tablePath的第一部分的indexPath是以

我有一个tableView,它分为2个部分。 func numberOfSections(in tableView: UITableView) -> Int { return 2 } 每个部分都有它自己的FetchResultController(FRC)。 这是我的CellForRoatAt函数 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "personCell", for: indexPath) as! PersonTableViewCell switch(indexPath.section) { case 0: print("this is section 0") let person = positiveFetchedResultsController.object(at: indexPath) cell.personName.text = person.name //print("\(person.name!) is the name") //print("\(person.statement!.count) postive person […]

核心数据严重的应用程序错误在controllerDidChangeContent

你好,我现在堆积在下面的错误。 CoreData:错误:严重的应用程序错误。 在调用-controllerDidChangeContent:期间,NSFetchedResultsController的委托捕获到exception。 无效的更新:无效的部分数量。 更新(7)之后,表格视图中包含的部分数量必须等于更新前的表格视图中包含的部分数量(6),加上或减去插入或删除的部分数目(0插入,0删除)。 与userInfo(null) 我的应用程序有多个部分tableView。 只有当我尝试插入新节logging时才会出现错误。 如果该部分已经存在,则不会发生错误。 相关的代码如下。 – (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.tableView beginUpdates]; } – (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { UITableView *tableView = self.tableView; DLog(@"newIndexPath %@",newIndexPath); switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeUpdate: [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; break; case […]

在属性上进行核心数据迁移时,从NSDate转换为NSString不适当地显示string

对于长期的问题,我感到抱歉。 我不知道如何解释这个没有包含大量的代码和图像。 我正在更新我的应用程序,因为我发现与date有关的问题,我不得不将属性从NSDate更改为NSString 。 我正在使用核心数据为我的应用程序。 应用程序的模型是: 交易实体 date实体 年实体 Year实体有一个名为yearOfEvent的NSDatetypes的属性,并且更新到我的应用程序(已经在应用程序商店中),我将yearOfEvent更改为NSString 。 一些研究和对另一个问题的答案告诉我,我必须自己做这个迁移。 这主要是工作,但还没有完成。 我的应用程序是一个双选项卡UITabBarController其中两个选项卡都是UITableViewControllers 。 首先是时间顺序条目的“时间线”。 第二个标签应该只显示已经input的年份; 所以如果用户使用2014,2013和2012的条目,则可以在“date”选项卡的单元格中看到这些条目,并且在点击该单元格时,会向您显示当年的条目。 这就是我想在这里改变的。 该应用程序由用户填充一些信息添加到UITextFields并从UIDatePicker中获取保存到Core-Data ,然后使用NSFetchedResultsController更新表。 问题 现在,当我从App Store中运行带有数据的应用程序,然后使用自定义迁移迁移到新版本的应用程序时,时间轴没有问题,但dateTableViewController的单元格的标签显示空白年。 单元格的数量是正确的,但是年份是空白的。 我在这个问题中遵循了被接受的答案: 多个通行证的核心数据迁移的例子或说明? 与代码的第一位,但我不知道在哪里把第二部分(代码的最后一部分)。 所以在我的Model类中,我有: – (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { // Create a new object for the model context NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager […]

date部分标题不起作用

我有一个按部分按datetableview的问题。 我拿了苹果的例子: DateSectionTitles 我不在乎一年。 我不需要一天一天的时间。 所以我适应了我的代码: 在我的CoreData类中: – (NSString *)sectionIdentifier { [self willAccessValueForKey:@"sectionIdentifier"]; NSString *tmp = [self primitiveSectionIdentifier]; [self didAccessValueForKey:@"sectionIdentifier"]; NSLog(@"!Temp"); if (!tmp) { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[self timeStamp]]; tmp = [NSString stringWithFormat:@"%d", ([components month]*100) + [components day]]; [self setPrimitiveSectionIdentifier:tmp]; } return tmp;} 在我的主控制器的titleForHeaderInSection方法中: NSInteger month […]

更新关系后,NSFetchedResultsController从UITableView中删除行

这是我如何设置NEFetchedResultsController : private func setupOnceFetchedResultsController() { if fetchedResultsController == nil { let context = NSManagedObjectContext.MR_defaultContext() let fetchReguest = NSFetchRequest(entityName: "WLWishlist") let dateDescriptor = NSSortDescriptor(key: "createdAt", ascending: false) fetchReguest.predicate = NSPredicate(format: "ANY users.identifier = %@", String(WLAppSettings.currentUser!.identifier) ) fetchReguest.sortDescriptors = [dateDescriptor] fetchReguest.fetchLimit = 10 fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchReguest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil) fetchedResultsController.delegate = self […]

iOS:保存托pipe对象上下文需要一段时间

奇怪的问题,奇怪的只有自从昨天。 我有一个获取结果控制器,您可以在其中重新sorting行没有任何问题。 应用程序重新启动后,一切正常,快速。 但是,如果您从此选项卡栏更改为另一个选项卡栏并编辑一些随机文本字段(甚至没有链接到核心数据,并且不会触发任何保存),重新sorting非常缓慢。 而且我只能把它缩小到保存的范围内。 但是现在我不知道该往哪里看。 有什么build议? 这是我的重新sortingfunction: – (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath; { if (self.activeField && [self.activeField isFirstResponder]){ [self.activeField resignFirstResponder]; } self.suspendAutomaticTrackingOfChangesInManagedObjectContext = YES; //Makes only a mutable copy of the array, but NOT the objects (references) within NSMutableArray *fetchedResults = [[self.fetchedResultsController fetchedObjects] mutableCopy]; // Grab the item we're moving NSManagedObject *resultToMove […]

使用NSFetchedResultsController移动行的方法及其委托不工作

我一直在试图按照这个教程重新安排在表视图中的行,而使用NSFetchedResultsController和NSFetchedResultsController委托,但我的项目是非常错误的。 会发生什么情况是,当我尝试重新排列一行并放下它时,这些行是随机的(可能不是随机的,但是我看不到模式来find问题)。 我的执行有什么问题? 表视图数据源: override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("RoutineCell", forIndexPath: indexPath) as! UITableViewCell var routine = fetchedResultsController.objectAtIndexPath(indexPath) as! Routine lastIndex++ // Configure the cell… cell.textLabel?.text = routine.name return cell } // Override to support conditional editing of the table view. override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: […]

NSFetchedResultsController不总是调用didChangeObject:atIndexPath:forChangeType:newIndexPath:for NSFetchedResultsChangeMove

我正在使用NSFetchedResultsController与sortDescriptors的请求来填充一个表中有很多的结果。 我注意到当发生一个从表底部附近移动一行到顶部的变化时, didChangeObject:atIndexPath:forChangeType:newIndexPath:根本不会被调用。 奇怪的是,我可以通过遍历所有提取的对象并在调用performFetch之后访问它们的任何属性来解决这个问题。 有关问题的任何提示,或者这只是一个晦涩的苹果错误? 这是我的代码: NSManagedObjectContext *context = [self managedObjectContext]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; request.entity = [NSEntityDescription entityForName:@"MyObject" inManagedObjectContext:context]; request.sortDescriptors = @[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:NO]]; request.fetchBatchSize = 20; NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; fetched.delegate = self; NSError *error = nil; if (![fetched performFetch:&error]) { NSLog(@"Unresolved error fetching objects: %@", […]

如何知道NSFetchedResultsChangeUpdate更改哪些属性?

我认为有一个controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:的问题controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:专门为NSFetchedResultsChangeUpdate :它不会告诉你什么样的变化导致此NSFetchedResultsChangeUpdate 。 我有一个非常复杂的实体。 只有一部分数据被用来填充我的表格视图单元格。 我不想更新我的单元格以进行任何不相关的属性更改 – 这是浪费资源。 那么如何才能知道哪些属性更改导致此NSFetchedResultsChangeUpdate以便我可以避免更新我的表视图单元格,如果它是不相关的?

在一个TableView中使用2个FRC并configurationFRCDelegate

我发现这个post的问题链接 ,我已经尽我所能将它从Obj-C转换为Swift。 当我添加一个新的实体,并尝试将其保存到CoreData,该应用程序崩溃,并突出显示这一行: modifiedIndexPath = NSIndexPath(row: (indexPath?.row)!, section: 0) 后面的绿色错误如下: Thread 1; EXC_BREAKPOINT (code=1, subcode=0x100008b118) Thread 1; EXC_BREAKPOINT (code=1, subcode=0x100008b118) 。 我不知道这是什么意思,输出面板也只显示(llbd)绿色。 编辑 – 我发现应用程序崩溃,因为indexPath?.row返回零。 我只是不知道为什么它返回零。 我的VC有两个部分是这样设置的: func numberOfSections(in tableView: UITableView) -> Int { return 2 } 标题的标题是这样设置的: // set the titles of the tables func tableView( _ tableView : UITableView, titleForHeaderInSection section: Int)->String? { […]