NSFetchedResultsController fetch request - updating predicate and UITableView

半城伤御伤魂 提交于 2019-12-06 03:16:03

You don't need to set up a NSFetchedResultsController for your task list. Since you are passing in the List entity, you can just ask the List entity for the tasks:

NSSet *tasks = [[self list] valueForKey:@"tasks"];
NSSortDescriptor *sort = ...;
NSArray *sorted = [[tasks allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
[self setTasks:sorted];

Then have the UITableviewDatasource methods run off of that tasks array.

Maybe I don't understand your setup completely, but

detailViewController.list.task

(or whatever that relationship is called) will return an NSSet of any Task objects that are associated with the List object.

Jean-Denis Muys

Well, I have a similar issue, and I posted my question at How to switch UITableView's NSFetchedResultsController (or its predicate) programmatically?.

After I posted it, I decided to try out your code. And you know what? It works, with only a small addition:

    [self.tableView reloadData];

Perhaps you can go back to your initial code and confirm.

Regards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!