2009-07-06 120 views
1

2009-07-06 06:49:13.666 Spark[9825:10b] -[<NSUserDefaultsController 0x137af0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hotKeyDisplayEntry.爲什麼Xcode中的這些錯誤意味着什麼?

2009-07-06 06:49:13.667 Spark[9825:10b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSUserDefaultsController 0x137af0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hotKeyDisplayEntry.'

編輯: 什麼,我認爲造成這個問題。

OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData) 
{ 
    EventHotKeyID hkCom; 
    GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom); 
    HotKeyController *controller = (HotKeyController *)userData; 
    int l = hkCom.id; 
    switch (l) { 
     case 1: [controller->window makeKeyAndOrderFront:NSApp]; 
      break; 
     case 2: [controller->searchWindow makeKeyAndOrderFront:nil]; 
      break; 
     case 3: [controller->entryWindow makeKeyAndOrderFront:nil]; 
      break; 
    } 
    return noErr; 
} 

- (void)awakeFromNib 
{ 
    //Register the Hotkeys 
    EventHotKeyRef gMyHotKeyRef; 
    EventHotKeyID gMyHotKeyID; 
    EventTypeSpec eventType; 
    eventType.eventClass=kEventClassKeyboard; 
    eventType.eventKind=kEventHotKeyPressed; 


    InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,(void *)self,NULL); 

    gMyHotKeyID.signature='htk1'; 
    gMyHotKeyID.id=1; 
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"]!=-999) { 
     RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersMain"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); 
    } 

    gMyHotKeyID.signature='htk2'; 
    gMyHotKeyID.id=2; 
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"]!=-999) { 
     RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersSearch"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); 
    } 

    gMyHotKeyID.signature='htk3'; 
    gMyHotKeyID.id=3; 
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"]!=-999) { 
     RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersEntry"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); 
    } 

} 

在NIB中,我還將文本字段連接到NSDefaultsController。

+0

它可能會幫助張貼圍繞異常的代碼(在調試器中查看回溯會有所幫助) – cobbal 2009-07-06 05:57:18

+0

這不僅僅是您最後一次嘗試此功能時的問題http://stackoverflow.com/questions/ 1072822/why-is-xcode-giving-me-these-errors? – Abizern 2009-07-06 07:04:45

+0

不,它是一組不同的代碼。 – Joshua 2009-07-06 07:09:13

回答

4

通常,這意味着您正試圖訪問某個對象的hotKeyDisplayEntry密鑰,但該對象沒有此類密鑰。你可能犯了一個錯字或次要的邏輯錯誤。

1

您(或某些代碼)似乎在您的類上使用鍵值編碼。我假設某個地方有一個hotKeyDisplayEntry ivar,可能是在一個筆尖和一個連接中定義的,但不在你的班級中?

而且閱讀:

Key-Value Coding in Cocoa (apple.com)

如果不是在它上面很可能要麼指定的伊娃觀察員或使用對象序列化和實際上沒有一個訪問方法,它,並因此引發異常。無論是或者,你需要擴大一點你實際上在做什麼來幫助你!