在即时更改NSFetchedResultsController中的排序 [英] Changing the Sorting in an NSFetchedResultsController on the fly

查看:169
本文介绍了在即时更改NSFetchedResultsController中的排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过某种分段控件来改变NSFetchController中的排序。要么排序A-> Z Z-> A类型的东西。

I'm trying to change the sorting in a NSFetchController on the fly, by some sort of segmented control. To either sort A->Z Z->A type thing.

我该怎么做呢?我正在关注Jeff Lamarche的例子:这里

What do I have to do to do this? I'm following Jeff Lamarche's example here: Here

我需要创建一个新的NSFetchedResultsController然后设置它,或者我只是做一个新的NSFetchRequest和做

Do I need to make a new NSFetchedResultsController and then set it, or do I just make a new NSFetchRequest and do

fetchedResultController.fetchRequest = newFetchRequest

然后我的表会自动更新?

and then my table will automatically update?

推荐答案

我遇到了同样的问题,我可以解决它只是设置排序描述符FetchRequestController的FetchRequest,然后执行fetch(performFetch),最后在表视图上重新加载数据。

I was stuck with the same problem and I could fix it with just setting the sort descriptors on the FetchRequestController's FetchRequest, then execute a fetch (performFetch) and finally reload the data on the table view.

NSArray *sortDescriptors = [NSArray arrayWithObject: sorter];
[[fetchedResultsController fetchRequest] setSortDescriptors:sortDescriptors];
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
        // Handle you error here
}
[sorter release];
[myTableView reloadData];

这是我处理更改排序的最简单的方法,或做任何其他花哨的对象处理。我不知道对性能的影响,如果表中的行集是巨大的,它可能会有影响。

This was the easiest way for me to deal with the change the sorting on the fly without dropping the FRC or do any other fancy object handling. I am not sure about the performance implications on that and it could have an impact if the set of rows in the table is huge.

这篇关于在即时更改NSFetchedResultsController中的排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆