从不同的viewControllers填充CoreData实体 [英] Fill a CoreData entity from different viewControllers

查看:162
本文介绍了从不同的viewControllers填充CoreData实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iPad应用程式上为我的资料库建立了不同实体的Core数据模型。我确实想从不同的viewControllers访问这些属性(和填充dBase)。例如,在viewController A中有UITextField,在viewController中有另一个UITextField。我想要获取的信息填充来自我的核心数据实体的不同属性...



这是可能吗?



我的问题:




  • 在viewController中声明类型为entity的对象

  • 我在viewController中也填充该实体的不同属性

  • I将对象(与我的实体相同的类型)存储在viewController中的NSMutableArray中

  • 我使用不同的方法在viewController A中保存和检索此NSMutableArray



    • 任何帮助或建议将不胜感激! : - )

      解决方案

      这里有MVC的力量。创建一个类(MVC的M的模型),它负责数据操作 - 获取,更新,删除等等...使这个类成为单例或者在AppDelegate中添加一个属性,并接收每个 UIViewController 你需要它。从其他地方收集视图控制器的所有数据 - 例如。一些字典或东西,然后调用你的数据类的一个方法,将插入数据,当准备好...好的设计总是导致更少的问题和困难的实施,也使得进一步更改UI易于,快速...


      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! :-)

      解决方案

      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...

      这篇关于从不同的viewControllers填充CoreData实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆