似乎无法摆脱键值编码兼容错误

时间:2011-07-29 16:32:43

标签: iphone objective-c xcode

当我尝试在我的应用程序中以模态方式显示视图控制器时,这是我得到的错误:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<KVPasscodeViewController 0x8b815a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key instructionLabel.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x011185a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0126c313 objc_exception_throw + 44
    2   CoreFoundation                      0x011184e1 -[NSException raise] + 17
    3   Foundation                          0x00aea677 _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x00aea5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x0056630c -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x0108e8cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x00564d23 -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x00566ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x0041c628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    10  UIKit                               0x0041a134 -[UIViewController loadView] + 120
    11  UIKit                               0x0041a00e -[UIViewController view] + 56
    12  UIKit                               0x00418482 -[UIViewController contentScrollView] + 42
    13  UIKit                               0x00428f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
    14  UIKit                               0x00427555 -[UINavigationController _layoutViewController:] + 43
    15  UIKit                               0x00428870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
    16  UIKit                               0x0042332a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
    17  UIKit                               0x0053e2e9 -[UILayoutContainerView layoutSubviews] + 226
    18  QuartzCore                          0x002a6a5a -[CALayer layoutSublayers] + 181
    19  QuartzCore                          0x002a8ddc CALayerLayoutIfNeeded + 220
    20  QuartzCore                          0x002a8ed0 -[CALayer layoutIfNeeded] + 111
    21  UIKit                               0x0041b58a -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:] + 587
    22  UIKit                               0x0039255f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 4347
    23  UIKit                               0x00619619 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1381
    24  UIKit                               0x0041e65d -[UIViewController presentModalViewController:withTransition:] + 3478
    25  DearMe                              0x00011ca1 -[NotificationViewController addPasscode] + 273
    26  UIKit                               0x0036a4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    27  UIKit                               0x003fa799 -[UIControl sendAction:to:forEvent:] + 67
    28  UIKit                               0x003fcc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    29  UIKit                               0x003fb7d8 -[UIControl touchesEnded:withEvent:] + 458
    30  UIKit                               0x0038eded -[UIWindow _sendTouchesForEvent:] + 567
    31  UIKit                               0x0036fc37 -[UIApplication sendEvent:] + 447
    32  UIKit                               0x00374f2e _UIApplicationHandleEvent + 7576
    33  GraphicsServices                    0x015f2992 PurpleEventCallback + 1550
    34  CoreFoundation                      0x010f9944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    35  CoreFoundation                      0x01059cf7 __CFRunLoopDoSource1 + 215
    36  CoreFoundation                      0x01056f83 __CFRunLoopRun + 979
    37  CoreFoundation                      0x01056840 CFRunLoopRunSpecific + 208
    38  CoreFoundation                      0x01056761 CFRunLoopRunInMode + 97
    39  GraphicsServices                    0x015f11c4 GSEventRunModal + 217
    40  GraphicsServices                    0x015f1289 GSEventRun + 115
    41  UIKit                               0x00378c93 UIApplicationMain + 1160
    42  DearMe                              0x000029df main + 127
    43  DearMe                              0x00002955 start + 53
    44  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

有关为何可能造成这种情况的任何想法?

编辑:给出错误的代码:

KVPasscodeViewController *passcodeController = [[KVPasscodeViewController alloc] init];
    passcodeController.delegate = self;
    UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:passcodeController];
    [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
    [passcodeNavigationController release];
    [passcodeController release];

2 个答案:

答案 0 :(得分:1)

这是因为你有一个插座指向该视图控制器的XIB中的'instructionLabel'。

答案 1 :(得分:1)

您的.xib文件最有可能指向不存在的标签。如果您在Interface Builder中添加UILabel,将其附加到存在instructionLabel的代码中,然后从代码中删除instructionLabel,则会发生这种情况,但忘记更新.xib }。