Fill a CoreData entity from different viewControllers

三世轮回 提交于 2019-12-25 04:59:53

问题


I built a Core data model with different entities for my database, on my iPad app. I do want to access these attributes (and fill the dBase) from different viewControllers. For instance, there are UITextFields in viewController A, and another UITextField in viewController. I'd like the seized information to fill different attributes from my Core Data entity...

Is that possible? What is the best practice to do so?

My problems :

  • I declare the objects with type "entity" in viewController A
  • I fill different attributes of this entity with the seized text, also in viewController A
  • I store the objects (same type as my entity) in a NSMutableArray in viewController A
  • I use different methods to save and retrieve this NSMutableArray in viewController A

Any help or advice would be appreciated! :-)


回答1:


Here comes the power of MVC. Make a class (model as of M of MVC) which is responsible for you data manipulation - fetching, updating, deleting, etc... Make this class either singleton or add a property in the AppDelegate and take in every UIViewController you need it. Collect all the data from the view controllers somewhere else - eg. some dictionary or something, then call a method of your data class that will insert the data, when ready... Good design always leads to less problems and difficulties with implementation and also makes further changes to the UI easy and fast...



来源:https://stackoverflow.com/questions/11048086/fill-a-coredata-entity-from-different-viewcontrollers

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