我很难理解如何使用新排序更新我的fetchedresults控制器。我在我的班级中初始化一个frc的标准方式。但是,如何用新的sortdecription修改fetchrequest?我的应用在appSettings中有一个排序选择器,用户可以随时更改。有没有办法更新frc动态?下面的代码是我在viewWillLoad回调中的,但它只是产生一个空白表。谢谢!动态更改FetchedResultsController的sortDescriptor。想法?
[self appSettingSortOrder];
if (sortOrderChanged) {
//Form a new fetchrequest for the FRC and reload the table.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Aircraft" inManagedObjectContext:managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:currentSortOrder ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSError *error = nil;
[fetchedResultsController performFetch:&error];
[self.tableView reloadData];
[fetchRequest release];
[sortDescriptor release];
[sortDescriptors release];
}
我也读过。所以看起来我需要用新的排序顺序创建一个新的FRC,并将其委派给具有回调的类,即self。可能谨慎地将当前的FRC分配给零。是/否? – Hal 2010-09-16 01:13:19