KVO observing of NSMangedObject in a UITableViewCell

落花浮王杯 提交于 2019-12-11 13:11:52

问题


I'm using a custom UITableViewCell to display properties of a NSMangedObject from my model. Each cell holds a reference to the managed object.

I also listen to changes in properties of the object by calling addObserver:… on the object.

The problem is that the objects can be removed from the model, and I want to unregister when this happens.

There is a similar question here, but the suggested solution there is to use prepareForDeletion on the object, and then manually notify the cells. This is not a very pretty solution.

I was wondering what is the recommended solution for these cases, and more then that - is observing KVO changes on the managed object is indeed the best approach to what I am trying to achieve.


回答1:


No, you should not use KVO for this. You need to use an NSFetchedResultsController, so that your tableview cells will be automatically updated using the NSFetchedResultsController delegate methods.

Please see the relevant documentation.



来源:https://stackoverflow.com/questions/8294453/kvo-observing-of-nsmangedobject-in-a-uitableviewcell

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