gpt4 book ai didi

iphone - ios 核心数据无法使用此代码找到实体名称 'Cartdetail' 的 NSManagedObjectModel

转载 作者:行者123 更新时间:2023-11-28 22:51:04 27 4
gpt4 key购买 nike

您好,我正在创建一个应用程序,它需要将我的标签内容中的数据保存到我的核心数据模型中,该模型被命名为 cart.xcdatamodeld,我的实体被命名为 Cartdetail。当我在我的应用程序中按下保存按钮时,我出现以下错误...

- (void)viewDidLoad {    
if (managedObjectContext == nil) {
managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate]managedObjectContext];
}
}

- (IBAction)SaveTest:(id)sender {

ViewController2 *second = (ViewController2 *)[NSEntityDescription insertNewObjectForEntityForName:@"Cartdetail" inManagedObjectContext:managedObjectContext];
}


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Cartdetail''
*** Call stack at first throw:
(
0 CoreFoundation 0x010265a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01444313 objc_exception_throw + 44
2 CoreData 0x00036ebb +[NSEntityDescription entityForName:inManagedObjectContext:] + 187
3 CoreData 0x0006e9eb +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 59
4 tablevc 0x00009c97 -[Description alertView:clickedButtonAtIndex:] + 519
5 UIKit 0x00621c5f -[UIAlertView(Private) _buttonClicked:] + 296
6 UIKit 0x002784fd -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x00308799 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x0030ac2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003097d8 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x0029cded -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x0027dc37 -[UIApplication sendEvent:] + 447
12 UIKit 0x00282f2e _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x01c34992 PurpleEventCallback + 1550
14 CoreFoundation 0x01007944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x00f67cf7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00f64f83 __CFRunLoopRun + 979
17 CoreFoundation 0x00f64840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00f64761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x01c331c4 GSEventRunModal + 217
20 GraphicsServices 0x01c33289 GSEventRun + 115
21 UIKit 0x00286c93 UIApplicationMain + 1160
22 tablevc 0x00001d4a main + 170
23 tablevc 0x00001c95 start + 53
)
terminate called throwing an exception

我是 iOS 新手..请帮助我..谢谢..

最佳答案

您可能还没有在 AppDelegate 中设置托管对象上下文!看一下apple提供的iPhoneCoreDataRecipes例子的AppDelegate实现: iPhoneCoreDataRecipes example

关于iphone - ios 核心数据无法使用此代码找到实体名称 'Cartdetail' 的 NSManagedObjectModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12004640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com