2014-09-10 109 views
-1

我不知道哪裏是我的問題,因爲實體「Utente」的存在。數據核心NSException

錯誤代碼:

 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente'' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000101bf0495 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x00000001016f099e objc_exception_throw + 43 
    2 CoreData       0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217 
    3 CoreData       0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30 
    4 VucmpraJson       0x000000010000514b -[LoginViewController login:] + 4843 
    5 UIKit        0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80 
    6 UIKit        0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 
    7 UIKit        0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203 
    8 UIKit        0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530 
    9 UIKit        0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701 
    10 UIKit        0x00000001002d66e4 -[UIWindow sendEvent:] + 925 
    11 UIKit        0x00000001002ae29a -[UIApplication sendEvent:] + 211 
    12 UIKit        0x000000010029baed _UIApplicationHandleEventQueue + 9579 
    13 CoreFoundation      0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    14 CoreFoundation      0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242 
    15 CoreFoundation      0x0000000101b9b46f __CFRunLoopRun + 767 
    16 CoreFoundation      0x0000000101b9ad83 CFRunLoopRunSpecific + 467 
    17 GraphicsServices     0x00000001040d0f04 GSEventRunModal + 161 
    18 UIKit        0x000000010029de33 UIApplicationMain + 1010 
    19 VucmpraJson       0x0000000100021d13 main + 115 
    20 libdyld.dylib      0x00000001025f15fd start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

代碼:

@property (nonatomic,strong) NSManagedObjectContext* managedObjectContext; 

。 。 。

NSManagedObjectContext *context = [self managedObjectContext]; 
NSManagedObject * Utente = [NSEntityDescription   insertNewObjectForEntityForName:@"Utente" inManagedObjectContext:context]; 
[Utente setValue: emailText.text forKey:@"email"]; 
NSError *error; 
    //[context save:&error]; 
    if (![context save:&error]) { 
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); 
} 

實體:Utente

屬性:電子郵件,密碼

THX得多傢伙

+0

凡設置'managedObjectContext'? – Larme 2014-09-10 12:48:09

回答

1

無不是合法的NSManagedObjectContext參數搜索實體名稱 'Utente'

表示您的管理對象上下文無。檢查self.managedObjectContext分配。

編輯

if (! [self managedObjectContext]) { 
    NSLog(@"You will receive your exception"); 
} else { 
    // Insert new entity into specified context 
} 
+0

怎麼檢查這個? sry,但是我第一次做核心數據 – 2014-09-10 11:56:37

+0

在呈現您的LoginViewController之前,您是否將值賦給了managedObjectContext? – voromax 2014-09-10 12:00:14

+0

沒有,...爲什麼?...... – 2014-09-10 12:03:23