0

大家好,我正在创建一个选项卡视图应用程序,在一个选项卡中,我有 7 个文本字段,我正在尝试使用“保存”按钮保存信息。在我的 controller.h 文件中的对象与实际文本字段之间建立连接后,当我选择包含所有这些内容的选项卡时,应用程序崩溃并转到跳板。我这里有调试:

2011-02-23 08:49:02.522 Tow Boat 911[19138:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4e0d1d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key colour.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00ec6be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00cbb5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x00ec6b21 -[NSException raise] + 17
    3   Foundation                          0x000286cf _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x0002863d -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x004a78d6 -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x00e3d2cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x004a62ed -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x004a8081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x00360a94 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    10  UIKit                               0x0035e709 -[UIViewController loadView] + 120
    11  UIKit                               0x0035e5e3 -[UIViewController view] + 56
    12  UIKit                               0x00371230 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
    13  UIKit                               0x0036fd86 -[UITabBarController transitionFromViewController:toViewController:] + 64
    14  UIKit                               0x00371b7e -[UITabBarController _setSelectedViewController:] + 263
    15  UIKit                               0x003719ed -[UITabBarController _tabBarItemClicked:] + 352
    16  UIKit                               0x002b0a6e -[UIApplication sendAction:to:from:forEvent:] + 119
    17  UIKit                               0x004ae1f2 -[UITabBar _sendAction:withEvent:] + 422
    18  UIKit                               0x002b0a6e -[UIApplication sendAction:to:from:forEvent:] + 119
    19  UIKit                               0x0033f1b5 -[UIControl sendAction:to:forEvent:] + 67
    20  UIKit                               0x00341647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    21  UIKit                               0x0033f16c -[UIControl sendActionsForControlEvents:] + 49
    22  UIKit                               0x002b0a6e -[UIApplication sendAction:to:from:forEvent:] + 119
    23  UIKit                               0x0033f1b5 -[UIControl sendAction:to:forEvent:] + 67
    24  UIKit                               0x00341647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    25  UIKit                               0x003401f4 -[UIControl touchesEnded:withEvent:] + 458
    26  UIKit                               0x002d50d1 -[UIWindow _sendTouchesForEvent:] + 567
    27  UIKit                               0x002b637a -[UIApplication sendEvent:] + 447
    28  UIKit                               0x002bb732 _UIApplicationHandleEvent + 7576
    29  GraphicsServices                    0x016dda36 PurpleEventCallback + 1550
    30  CoreFoundation                      0x00ea8064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    31  CoreFoundation                      0x00e086f7 __CFRunLoopDoSource1 + 215
    32  CoreFoundation                      0x00e05983 __CFRunLoopRun + 979
    33  CoreFoundation                      0x00e05240 CFRunLoopRunSpecific + 208
    34  CoreFoundation                      0x00e05161 CFRunLoopRunInMode + 97
    35  GraphicsServices                    0x016dc268 GSEventRunModal + 217
    36  GraphicsServices                    0x016dc32d GSEventRun + 115
    37  UIKit                               0x002bf42e UIApplicationMain + 1160
    38  Tow Boat 911                        0x00001df8 main + 102
    39  Tow Boat 911                        0x00001d89 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.

感谢大家提前提供任何帮助!

4

1 回答 1

0

由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键颜色的键值编码。

在这种情况下,请检查以下内容:

  1. 确保您没有拼错您尝试访问的键,即颜色。

  2. 您尝试访问的类属性(即颜色)应该符合键值。您可以将属性声明为标题中的属性并在实现文件中合成相同的属性。不要在属性声明中更改 getter 和 setter 的默认名称。默认方法名称/签名符合 KVC。关于 KVC 的 Apple 文档涵盖了访问器方法代码:http: //developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/Overview.html

  3. 如果您使用核心数据,请确保正在访问的属性存在于相应的头文件中,并且其代码也在实现文件中。您稍后可能会将此属性添加到模型中并且没有更新生成的头文件和实现文件。

在没有答案的情况下看到这篇文章,所以我想我会做出一个可能对其他人有帮助的回应。

于 2011-05-25T03:23:19.027 回答