安装程序:带FRC的UITableView。行是简单的文本内容列表,用户可以通过刷新来获取最新的内容。NSFetchedResultsController(和UITableView)委托方法调用正在增长和增长
我看到奇怪的行为,其中cellForRow被称为每行,多次。所以我看到它为0,0 0,1 0,2 0,3(可见行),但这4行都具有多次调用的cellForRow。但是,第一次查看列表时,他们只会被调用一次。第二次,第二次,等等。到第七次,在用户看到内容之后,它在幕后继续尝试和反复配置单元,并最终崩溃。
所以,如果你去的任何内容列表,它击中的服务器,下载的故事,创造NSMOs和显示器。在日志中,我看到configureCell为每个可见行调用一次。如果我刷新,我看到相同。但如果我导航到不同的屏幕,然后回来,当我拉刷新我注意到cellforrow被称为每行两次。如果我继续这个离开和回来的过程,每次我都会这样做,cellforrow被称为额外的时间。记录一些获取的结果控制器委托方法,我看到每个cellforrow调用之前会更改内容。有人可以帮助我确定为什么我的cellforrow方法被称为越来越多的时间?
一个想法是我设立FRC的方式。我遵循像CoreDataBooks这样的代码并将事物移至viewdidload,但仍然看到问题。
我在.H和在.M属性有什么我认为是一个标准设置:
- (NSFetchedResultsController *)fetchedResultsController
{
//NSLog(@"fetchedresulscontroller");
if (_fetchedResultsController != nil)
{
return _fetchedResultsController;
}
// initialize fetch request. setup predicate, sort, etc.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"date" cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
// perform actual fetch. delegate methods take it from here
NSError *fetchError = nil;
if (![self.fetchedResultsController performFetch:&fetchError])
{
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", fetchError, [fetchError userInfo]);
abort();
}
return _fetchedResultsController;
}
我怀疑它可能有事可做当你运行你'NSFetchedResultsController'用?哪一种TVC生命周期方法? – andrewbuilder
那么你有一个本地变量,坚持在内存中的FRC?另外,您何时设置FRC - 即 - 您的代码的哪部分发生了这种情况? – andrewbuilder
我有一个属性,然后在上面发布的 - (NSFetchedResultsController *)fetchedResultsController中设置FRC。谢谢! – skinsfan00atg