在 appdelegate 加载我的 mainWindow.xib 之前设置 coredata
我在 appDelegate 中设置了 coredata,但它首先加载该 xib 文件中的 mainWindow.xib 和相应的控制器+视图。这些控制器需要有一个 ManagedObjectContext 才能正确加载。在 xib 解档后,它会运行我的 appDelegate 中的代码。
我如何设置 coredata 然后加载 mainWIndow.xib?或者只是确保 coredata 在解压我的 mainWindows.xib 之前正确初始化?
I have setup coredata in my appDelegate, but it first loads the mainWindow.xib and the corresponding controllers+views in that xib file. Those controllers need to have a managedObjectContext to load properly. And after the xib is unarchived it runs the code in my appDelegate.
How can i setup my coredata and then load the mainWIndow.xib? Or just make sure coredata is initialized properly before unarchiving my mainWindows.xib?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
UIApplicationDelegate
子类上重写awakeFromNib
,并在那里设置 Core Data。一旦所有对象从 nib 文件中取消归档,但在它们的实例开始执行其工作之前,就会调用此方法。将awakeFromNib
视为在实例开始运行之前调整任何行为的最后机会。注意:
awakeFromNib
时,您必须调用[super awakeFromNib]
,否则您的超类可能无法正确初始化。awakeFromNib
的调用顺序未定义,因此您永远不能从awakeFromNib
内向同一 Nib 的任何其他对象发送消息。作为奖励,这也意味着awakeFromNib
保证在同一 Nib 中的任何其他对象需要您的服务并向您发送任何消息之前运行。You could override
awakeFromNib
on yourUIApplicationDelegate
subclass, and setup Core Data there. This method will be called once all objects has been unarchived from your nib file, but before their instances begin to do their work. SeeawakeFromNib
as your last chance to tweak any behavior before the instances start running.Observe:
awakeFromNib
you must call[super awakeFromNib]
, or else your superclass might not initialize properly.awakeFromNib
is undefined, so you may never send messages to any other objects from the same Nib from withinawakeFromNib
. As a bonus this also means thatawakeFromNib
is guaranteed to run before any other object in the same Nib needs your services and sends any messages to you.