Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 核心数据关系、NSPredicates和NSFetchedResultsController_Iphone_Objective C_Cocoa_Uitableview_Nsfetchedresultscontroller - Fatal编程技术网

Iphone 核心数据关系、NSPredicates和NSFetchedResultsController

Iphone 核心数据关系、NSPredicates和NSFetchedResultsController,iphone,objective-c,cocoa,uitableview,nsfetchedresultscontroller,Iphone,Objective C,Cocoa,Uitableview,Nsfetchedresultscontroller,这一整天都快把我逼疯了 我有一个奇怪的错误,我想我已经缩小到一个NSPredicate。我有两个实体:列表和个人。列表与称为persons的人有对多关系,而Person与称为List的列表有对多关系 我将列表对象传递给我的tableview控制器。然后,我希望tableview控制器显示属于该列表对象的人员。我正在使用NSFetchedResultsController执行此操作 在设置NSFRC时,我有以下代码(为了清楚起见,省略了内存管理)。有问题的列表是myList: // Create

这一整天都快把我逼疯了

我有一个奇怪的错误,我想我已经缩小到一个NSPredicate。我有两个实体:列表和个人。列表与称为persons的人有对多关系,而Person与称为List的列表有对多关系

我将列表对象传递给我的tableview控制器。然后,我希望tableview控制器显示属于该列表对象的人员。我正在使用NSFetchedResultsController执行此操作

在设置NSFRC时,我有以下代码(为了清楚起见,省略了内存管理)。有问题的列表是
myList

// Create the request and set it's entity
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

// Create a predicate to get the persons that belong to this list
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY lists == %@)", myList];

// Assign this predicate to the fetch request
[fetchRequest setPredicate:predicate];

// Define some descriptors
NSSortDescriptor *locationDescriptor = [[NSSortDescriptor alloc] initWithKey:@"location" ascending:YES];
NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:locationDescriptor, lastNameDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

// Create and initialize the fetch results controller.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"location" cacheName:nil];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;
我认为问题在于这一行(因为如果我删除它,它就会消失):

当父视图将
myList
传递给tableview控制器时,模拟器就会挂起。控制台中没有崩溃日志或其他内容。这几乎就像是花了很长时间来整理NSFRC


我使用的谓词有问题吗?

当您可以从传递到tableViewController的列表中获取
人员时,是否需要使用
NSFetchedResultsController

NSSet *people = myList.persons;

您是正确的,您只需使用
myList.persons
,在这种情况下不需要使用
NSFetchedResultsController

感谢您关于:使用NSSet的建议。经过数小时的错误跟踪,我意识到问题在于我的cellForIndexPath表视图方法(因此,与NSFRC无关)。

您的评论令人困惑。我的回答提供了另一种需要重新设计tableViewController的方法。
NSSet *people = myList.persons;