Tag: nsfetchedresultscontroller

使用NSFetchedResult控制器和每个月的部分标题

可能重复: 使用fetchedresultcontroller为每个月设置一个不同的部分 我试图将我的UITableview分成每个月的部分。 我开始使用苹果的DateSectionTitles例子。 首先,我在我的coredata中添加了一个属性“sectionIdentifier”。 然后在我的managedobject子类中,我添加了这个方法。 – (NSString *)sectionIdentifier { // Create and cache the section identifier on demand. [self willAccessValueForKey:@"sectionIdentifier"]; NSString *tmp = [self primitiveSectionIdentifier]; [self didAccessValueForKey:@"sectionIdentifier"]; if (!tmp) { /* Sections are organized by month and year. Create the section identifier as a string representing the number (year * 1000) + month; this […]

NSFetchedResultsController似乎是插入空的对象数组?

我不确定发生了什么问题。 我的数据模型中有一个实体,名为Quote,其中大约3000个存储在.sqlite中。 我只是试图通过NSFetchedResultsController的方式获得这些实体的属性之一到一个UITableView的单元格。 我得到的错误是在这行代码: NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest managedObjectContext: [self managedObjectContext] sectionNameKeyPath: nil cacheName: @""]; 看来问题在于它试图将一个空对象加载到数组中。 我猜这意味着它没有find.sqlite文件中的对象。 这可能是这样吗? 如果是这样,我该如何开始追查为什么可能呢? 这里有一些代码,如果你需要更多,请问: 从AppDelegate.m: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UINavigationController *nav = (UINavigationController *) self.window.rootViewController; FQQuotesTableViewController *quotesTableViewController = (FQQuotesTableViewController *) [[nav viewControllers] objectAtIndex: 0]; quotesTableViewController.managedObjectContext = self.managedObjectContext; quotesTableViewController.test = @"Hello!"; return YES; } – […]

获取结果时发生崩溃控制器在保存后台MOC后更新表

我有一个连接到一个FRC(Fetched Results Controller)的tableView,我也有两个上下文,分别是在私有队列中初始化的backgroundContext和在主队列上初始化的mainContext。 我还设置了didSaveNotification将对象从一个上下文传递给另一个上下文。 当我在backgroundContext保存一些数据,它保存成功和FRC更新,但如果我再次重复该过程应用程序崩溃与一个错误 'ALL或ANY操作符的左侧必须是NSArray或NSSet。 保存是通过模态显示的forms完成的。 相同的viewController工作正常,如果出现在其他viewControllers。 但只在一个特定的一个崩溃。 但是再次提交表单没有其他额外的东西正在做。 这是我的整个崩溃报告。 由于未捕获exception“NSInvalidArgumentException”而终止应用程序,理由:'ALL或ANY操作符的左侧必须是NSArray或NSSet。 *第一个抛出调用栈:(0 CoreFoundation 0x0000000103575495 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000102fbb99e objc_exception_throw + 43 2基金会 0x00000001003c706b – [NSPredicateOperator performOperationUsingObject:andObject:] + 826 3 Foundation 0x00000001003c6c1e – [NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 314 4 Foundation 0x00000001003c6ae2 – [NSPredicate evaluateWithObject:] + 19 5 CoreData 0x0000000102d61d06 – [NSFetchedResultsController(PrivateMethods)_objectInResults:] + 102 6 […]

RESTKIT + COREDATA = FetchResultsController问题

您好,我有NSFetchedResultsController由Web应用程序的数据填充问题。 为了从服务器端映射表,我使用了RestKit框架。 当我更改当前用户时,我的UITableViewController的数据仍然呈现来自之前用户的单元格,但没有从服务器接收到信息 – 只是默认的标签文本值。 但是,单元格的数量与以前的用户相同。 它发生在我身上只有在其他一切UITableViewController工作正常。 你可以看看我的NSFetchedResultsController委托方法,并注销方法,并解释我是什么做错了,或者我应该改变,使其工作? – (void)viewDidLoad { [super viewDidLoad]; _managedObjectContext = [[DateModel sharedDataModel]objectStore].mainQueueManagedObjectContext; [self loadAlerts]; } #pragma mark – TableView Data Source – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [[self.fetchedResultsController sections] count]; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections[section]; return [sectionInfo numberOfObjects]; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { […]

如何检查UICollectionView中插入和删除的项目,看到意外的删除项目

我在这个特定的情况下努力集成UICollectionView和UICollectionView 。 在我的视图控制器中,我获取父实体,但在集合视图中显示其多个子实体。 在这个视图控制器(使用insertNewObjectForEntityForName )中创build一个新的Parent实体并自动创build一个Child实体并将其添加到具有addChildObject的父实体时,我可以通过按下一个button来添加更多的Child实体,并成功保存该对象。 不幸的是,由于某种原因, NSFetchedResultsControllerDelegate方法不被调用,具体来说, controllerDidChangeContent从不被调用,集合视图不会被更新。 当我获取一个已经存在的Parent实体,然后尝试通过添加新的Child对象来更改它时,该应用程序崩溃,出现以下exception: *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.17/UICollectionView.m:4211 最后给出这个错误: CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to controllerDidChangeContent:. Invalid update: invalid number of items in section 0. The number of items contained in an existing section after […]

NSPredicate用于检测属性的类

我有事件,每个事件与NSManagedObject娱乐有一对一的关系,娱乐有多对多的关系,并有NSSet事件 @interface Event : NSManagedObject @property (nonatomic, retain) NSDate *creationDate; @property (nonatomic, retain) NSDate * date; @property (nonatomic, retain) NSString * objectId; @property (nonatomic, retain) NSString * price; @property (nonatomic, retain) Entertainment *entertainment; @property (nonatomic, retain) Place *place; @property (nonatomic, retain) NSString *townName; – (void)fillProperties:(NSDictionary *)JSON; @end @interface Entertainment : NSManagedObject @property (nonatomic, retain) NSString […]

NSFetchedResultsController产生的部分的顺序?

sectionNameKeyPath是否将由sectionNameKeyPath标识的属性的值始终以升序sectionNameKeyPath给段落? 例如,如果我的sectionNameKeyPath是值为@(YES) , @(NO) , @(YES)的(可选)布尔属性,则第一部分将接收一行(因为NO对应于0 ),第二部分接收两个因为YES对应于1 )? 那么是这样的,如果是的话,是否可以改变顺序(而不引入另一个“反转”的属性)?

使用UICollectionView和NSFetchedResultsController不保存

我在github上使用项目查找,让我使用UICollectionView和UICollectionView ,项目是这样的 在我的项目中,我有一个核心数据与两个实体, Element和Document , Element和Document之间有一对多的关系,所以一个Element可以有更多的Document ,但一个Document只能有一个Element ,然后我这样做AppDelegate : – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. ElementViewController *elementView = [[ElementViewController alloc] initWithNibName:@"ElementViewController" bundle:nil]; elementView.managedObjectContext = self.managedObjectContext; DocumentViewController *documentView = [[DocumentViewController alloc] initWithNibName:@"DocumentViewController" bundle:nil]; documentView.managedObjectContext = self.managedObjectContext; elementView.documentView = documentView; UINavigationController *navController […]

数据未更新的NSFetchedResultsController

我正在制作一个从服务器获取产品列表的应用程序。 然后我将它们存储在Core Data数据库中,并使用GMGridView呈现它们,数据源是NSFetchedResultsController 。 当我更改服务器中的产品详细信息时,我希望我的iOS应用程序同步并进行必要的更改,以便实现NSFetchedResultsControllerDelegate方法。 我应该如何正确更新我的gridView? – (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { switch(type) { case NSFetchedResultsChangeInsert: [_currentData insertObject:anObject atIndex:newIndexPath.row]; [_currentData removeObjectAtIndex:indexPath.row]; [_gmGridView insertObjectAtIndex:newIndexPath.row animated:YES]; [_gmGridView removeObjectAtIndex:indexPath.row animated:YES]; [_gmGridView reloadObjectAtIndex:newIndexPath.row animated:YES]; [_gmGridView reloadObjectAtIndex:indexPath.row animated:YES]; [_gmGridView reloadData]; //[self updatePageControl]; break; case NSFetchedResultsChangeDelete: [_currentData removeObjectAtIndex:indexPath.row]; [_gmGridView removeObjectAtIndex:indexPath.row animated:YES]; //[self updatePageControl]; [_gmGridView reloadInputViews]; [_gmGridView reloadData]; […]

NSFetchedResults控制器在不同的视图控制器互相更新?

好吧,我越来越一般这个问题,因为我已经注意到我的应用程序由于这个几个滞后。 我已经注意到重新sorting的问题,但也发生在其他地方。 我有一个CoreDataViewController类,所有我的表视图控制器的子类。 在这个类中,我基本上拥有所有的NSFetchedResultsController委托方法,就像它们在苹果文档中一样。 然后我试着找出这个NSFetchedResultsController发现变化的频率,以找出我的时间滞后的地方: – (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { if(self.suspendAutomaticTrackingOfChangesInManagedObjectContext) return; NSLog(@"ControllerDidChangeContent"); TICK; [self.tableView endUpdates]; TOCK; } 所以例如在我的视图控制器A中,我有这个获取请求(从viewDidLoad调用): – (void)setupFetchedResultsController { //NSError *error = nil; NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"SpendingCategory"]; request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"position" ascending:YES]]; //[self.mainCategory.managedObjectContext executeFetchRequest:request error:&error]; request.predicate = [NSPredicate predicateWithFormat:@"belongsToMainCategory = %@", self.mainCategory]; self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request managedObjectContext:self.mainCategory.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; } 如果我在此视图控制器中更改我的对象的属性,则我的日志只会打印出“ControllerDidChangeContent”注释。 […]