开发者

NSFetchedResultsController and UITableView animation issue

开发者 https://www.devze.com 2023-04-06 02:12 出处:网络
I\'m having a visual issue while using an NSFetchedResultsController with a UITableView. I\'ve discovered that the iPhoneCoreDataRecipes sample code from Apple exhibits the same problem. I\'m looking

I'm having a visual issue while using an NSFetchedResultsController with a UITableView. I've discovered that the iPhoneCoreDataRecipes sample code from Apple exhibits the same problem. I'm looking for a workaround.

In iPhoneCoreDataRecipes, a UITableView displays a list of recipes. There is an "Add" button that inserts a new recipe object into the managed object context and then modally presents a view controller to edit that new object.

The insertion of the new recipe object causes NSFetchedResultsController to update the table. When a user taps the "Add" button, an empty row is inserted into the table view (and a row insertion animation occurs) at the same time that the new modal view controller is being shown. It lo开发者_开发知识库oks sloppy to me. I'd rather the new row not appear until the modal view controller has been dismissed.

I'd appreciate any suggestions.


The problem goes away if you use a separate Managed Context for editing the object. So in your modal controller create a new context and assign it to the shared persistent store. This will then not notify the fetched controller of any addition till it's time to close the modal view controller at which point you should perform a 'save' and then a 'merge' back on the main managed context.

0

精彩评论

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

关注公众号