我有一个基于 Utility 模板的应用程序(您可以在其中翻转 View 以查看另一个 View )。在第一个 View 中有一个登录屏幕,然后翻转过来显示一个 UITabBar 风格的界面。
我无法弄清楚如何将 managedObjectContext 从 App Delegate(创建它的地方)一直传递到每个选项卡栏的 View 。
App Delegate 的 managedObjectContext 被传递给 FrontLoginViewController,后者被传递给 BackViewTabBarViewController .. 下一步在哪里?
BackViewTabBarViewController nib 有一个 UITabBarController,每个选项卡都有一个 UINavigationController。
最佳答案
听起来 managedObjectContext 是在您的 AppDelegate 中定义的。如果是这样,那么......
从你想要的任何 viewController... 只需调用
MyApplicationDelegate *appDelegate = (MyApplicationDelegate *)[[UIApplication sharedApplication] delegate];
然后使用...
appDelegate.managedObjectContext
每当您需要 managedObjectContext 时。将 MyApplicationDelegate 更改为您的 AppDelegate,您应该可以开始了。
关于iphone - 将 managedObjectContext 传递给 UITabBarController 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3970952/