开发者

Changing core data predicate from setEditing

My app maintains a list of data of which some rows may be hidden by the user. The hide/show button is in an editing panel that is accessed by putting the tableview into editing mode and then selecting the row to be edited. This means that in editing mode all rows need to show up, even those that are normally hidden; otherwise there would be no way to unhide them.

I implemented this by setting fetchedResultsController to nil and reloading the table within setEditing, and then modifying the code that builds the predicate for the fetchedResultsController to check if the table is in editing mode and if so, skipping the part of the predicate that excludes hidden lists. So when the user touches the Edit button the table reloads with all rows on the way into editing mode, and reloads again with only unhidden rows on the way back out.

This works fine except that it has killed the animation one usually sees while going into an开发者_StackOverflow社区d out of editing mode. The extra reload has made it look abrupt. It makes no difference if I do the reload before or after the call to [super setEditing:animated].

Is there a better way or place to do this?


From: http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html

Modifying the Fetch Request You cannot simply change the fetch request to modify the results. If you want to change the fetch request, you must:

  1. If you are using a cache, delete it (using deleteCacheWithName:). Typically you should not use a cache if you are changing the fetch request.
  2. Change the fetch request.
  3. Invoke performFetch:

See if that works better, vs. destroying the controller and reloading the table.


Make your CD object include a visibility attribute. When you go into editing mode, flip the attributes for all hidden cells. Make the predicate for the fetchedResultsController include the visibility attribute. It will automatically add the table cells if you have implemented the call-backs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜