iPhone:无法使用 appDelegate 访问 NSManagedObjectContext
我之前就开始进行 iPhone 开发,并尝试在我的应用程序中实现核心数据。
在执行 FetchRequest 的过程中,我陷入了以下代码...
MYAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
调试时显示以下错误...
Program received signal: "EXC_BAD_ACCESS"
当我运行应用程序时,它只是崩溃。
当我在调试模式下按“继续”按钮时,此错误一次又一次出现。
我尝试将我的代码更改为这个......
NSManagedObjectContext *context = [(MyAppDelegate *)[[UIApplication sharedApplication\ delegate] managedObjectContext];
这可以让应用程序运行,但是当我按下模拟器主页按钮时,控制台中会显示相同的错误。
这里可能出了什么问题?
I have started with iPhone development sometime back and I am trying to implement core data in my application.
In the process of executing FetchRequest I am stuck at following code...
MYAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
While debugging the following error is displayed...
Program received signal: "EXC_BAD_ACCESS"
When I run the app, it just crashes.
This error appears again and again when I press 'continue' button in debug mode.
I tried changing my code, to this.....
NSManagedObjectContext *context = [(MyAppDelegate *)[[UIApplication sharedApplication\ delegate] managedObjectContext];
This lets the app run but when I press the Simulator home button, the same error is displayed in console.
What could be going wrong over here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的应用程序委托有一个公共访问器方法。我会像这样在 AppDelegate.m 的顶部实现它,
然后您可以使用以下方式访问它:
Make sure you have a public accessor method for your application delegate. I would implement it like so, at the top of your AppDelegate.m
You may then access it using: