将标签链接到 IBOutlet 会给出 NSUnknownKeyException

发布于 2024-11-07 12:43:07 字数 5857 浏览 0 评论 0原文

我创建了一个 TabBarView。在其中一个选项卡上,我有一个带有多个标签的视图。效果很好。

当我将 Interface Builder 中的标签连接到文件的所有者(相应的 IBOutlet)时,当我打开该选项卡时,应用程序崩溃并出现以下错误:

2011-05-15 18:36:29.070 AeroNav[958:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x18afe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key speedLabel.'
*** Call stack at first throw:
(
0   CoreFoundation                      0x312a664f __exceptionPreprocess + 114
1   libobjc.A.dylib                     0x34a07c5d objc_exception_throw + 24
2   CoreFoundation                      0x312a63cd -[NSException dealloc] + 0
3   Foundation                          0x351c7edb -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
4   Foundation                          0x351809cb _NSSetUsingKeyValueSetter + 90
5   Foundation                          0x35180217 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
6   Foundation                          0x3516242f -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
7   UIKit                               0x369848df -[UIRuntimeOutletConnection connect] + 66
8   CoreFoundation                      0x3123ed7b -[NSObject(NSObject) performSelector:] + 18
9   CoreFoundation                      0x3123e99d -[NSArray makeObjectsPerformSelector:] + 388
10  UIKit                               0x36983847 -[UINib instantiateWithOwner:options:] + 586
11  UIKit                               0x36984e09 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
12  UIKit                               0x368fe5e9 -[UIViewController _loadViewFromNibNamed:bundle:] + 36
13  UIKit                               0x368cbfa5 -[UIViewController loadView] + 80
14  UIKit                               0x367b0ebf -[UIViewController view] + 30
15  UIKit                               0x367ee1db -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 66
16  UIKit                               0x367ee18d -[UITabBarController transitionFromViewController:toViewController:] + 32
17  UIKit                               0x367eda33 -[UITabBarController _setSelectedViewController:] + 186
18  UIKit                               0x36872ceb -[UITabBarController setSelectedViewController:] + 14
19  UIKit                               0x36872be7 -[UITabBarController _tabBarItemClicked:] + 226
20  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
21  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
22  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
23  UIKit                               0x36872a8b -[UITabBar _sendAction:withEvent:] + 270
24  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
25  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
26  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
27  UIKit                               0x36796e3b -[UIControl sendAction:to:forEvent:] + 38
28  UIKit                               0x36796b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
29  UIKit                               0x367d0bd9 -[UIControl sendActionsForControlEvents:] + 16
30  UIKit                               0x36872815 -[UITabBar(Static) _buttonUp:] + 80
31  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
32  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
33  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
34  UIKit                               0x36796e3b -[UIControl sendAction:to:forEvent:] + 38
35  UIKit                               0x36796b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
36  UIKit                               0x36797423 -[UIControl touchesEnded:withEvent:] + 342
37  UIKit                               0x36795bf5 -[UIWindow _sendTouchesForEvent:] + 368
38  UIKit                               0x3679556f -[UIWindow sendEvent:] + 262
39  UIKit                               0x3677e313 -[UIApplication sendEvent:] + 298
40  UIKit                               0x3677dc53 _UIApplicationHandleEvent + 5090
41  GraphicsServices                    0x36452e77 PurpleEventCallback + 666
42  CoreFoundation                      0x3127da97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
43  CoreFoundation                      0x3127f83f __CFRunLoopDoSource1 + 166
44  CoreFoundation                      0x3128060d __CFRunLoopRun + 520
45  CoreFoundation                      0x31210ec3 CFRunLoopRunSpecific + 230
46  CoreFoundation                      0x31210dcb CFRunLoopRunInMode + 58
47  GraphicsServices                    0x3645241f GSEventRunModal + 114
48  GraphicsServices                    0x364524cb GSEventRun + 62
49  UIKit                               0x367a8d69 -[UIApplication _run] + 404
50  UIKit                               0x367a6807 UIApplicationMain + 670
51  AeroNav                             0x00002423 main + 70
52  AeroNav                             0x000023d8 start + 40
)
terminate called after throwing an instance of 'NSException'

我已读到它可能与 xib 不匹配(正确连接)与其相关视图控制器。我不知道如何检查或解决这个问题?

这就是我的头文件的样子:

//Stats.h
#import <UIKit/UIKit.h>
@interface Stats : UIViewController
{
    IBOutlet UILabel *speedLabel;
    IBOutlet UILabel *headingLabel;
}
@end

如果有人有任何提示或其他类似帖子的链接,我将不胜感激!

先感谢您!

I have created a TabBarView. On one of the tabs, I have a View with several Labels on it. It works fine.

When I connect the Labels in Interface Builder to the File's Owner (the corresponding IBOutlets) then the App crashes with the following error when I open that tab:

2011-05-15 18:36:29.070 AeroNav[958:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x18afe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key speedLabel.'
*** Call stack at first throw:
(
0   CoreFoundation                      0x312a664f __exceptionPreprocess + 114
1   libobjc.A.dylib                     0x34a07c5d objc_exception_throw + 24
2   CoreFoundation                      0x312a63cd -[NSException dealloc] + 0
3   Foundation                          0x351c7edb -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
4   Foundation                          0x351809cb _NSSetUsingKeyValueSetter + 90
5   Foundation                          0x35180217 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
6   Foundation                          0x3516242f -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
7   UIKit                               0x369848df -[UIRuntimeOutletConnection connect] + 66
8   CoreFoundation                      0x3123ed7b -[NSObject(NSObject) performSelector:] + 18
9   CoreFoundation                      0x3123e99d -[NSArray makeObjectsPerformSelector:] + 388
10  UIKit                               0x36983847 -[UINib instantiateWithOwner:options:] + 586
11  UIKit                               0x36984e09 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
12  UIKit                               0x368fe5e9 -[UIViewController _loadViewFromNibNamed:bundle:] + 36
13  UIKit                               0x368cbfa5 -[UIViewController loadView] + 80
14  UIKit                               0x367b0ebf -[UIViewController view] + 30
15  UIKit                               0x367ee1db -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 66
16  UIKit                               0x367ee18d -[UITabBarController transitionFromViewController:toViewController:] + 32
17  UIKit                               0x367eda33 -[UITabBarController _setSelectedViewController:] + 186
18  UIKit                               0x36872ceb -[UITabBarController setSelectedViewController:] + 14
19  UIKit                               0x36872be7 -[UITabBarController _tabBarItemClicked:] + 226
20  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
21  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
22  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
23  UIKit                               0x36872a8b -[UITabBar _sendAction:withEvent:] + 270
24  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
25  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
26  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
27  UIKit                               0x36796e3b -[UIControl sendAction:to:forEvent:] + 38
28  UIKit                               0x36796b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
29  UIKit                               0x367d0bd9 -[UIControl sendActionsForControlEvents:] + 16
30  UIKit                               0x36872815 -[UITabBar(Static) _buttonUp:] + 80
31  CoreFoundation                      0x31216571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
32  UIKit                               0x36796ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
33  UIKit                               0x36796e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
34  UIKit                               0x36796e3b -[UIControl sendAction:to:forEvent:] + 38
35  UIKit                               0x36796b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
36  UIKit                               0x36797423 -[UIControl touchesEnded:withEvent:] + 342
37  UIKit                               0x36795bf5 -[UIWindow _sendTouchesForEvent:] + 368
38  UIKit                               0x3679556f -[UIWindow sendEvent:] + 262
39  UIKit                               0x3677e313 -[UIApplication sendEvent:] + 298
40  UIKit                               0x3677dc53 _UIApplicationHandleEvent + 5090
41  GraphicsServices                    0x36452e77 PurpleEventCallback + 666
42  CoreFoundation                      0x3127da97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
43  CoreFoundation                      0x3127f83f __CFRunLoopDoSource1 + 166
44  CoreFoundation                      0x3128060d __CFRunLoopRun + 520
45  CoreFoundation                      0x31210ec3 CFRunLoopRunSpecific + 230
46  CoreFoundation                      0x31210dcb CFRunLoopRunInMode + 58
47  GraphicsServices                    0x3645241f GSEventRunModal + 114
48  GraphicsServices                    0x364524cb GSEventRun + 62
49  UIKit                               0x367a8d69 -[UIApplication _run] + 404
50  UIKit                               0x367a6807 UIApplicationMain + 670
51  AeroNav                             0x00002423 main + 70
52  AeroNav                             0x000023d8 start + 40
)
terminate called after throwing an instance of 'NSException'

I have read that it can be related to the xib not matching (correctly connected) to its view controller. I have no idea how to check or fix that?

This is how my header file looks:

//Stats.h
#import <UIKit/UIKit.h>
@interface Stats : UIViewController
{
    IBOutlet UILabel *speedLabel;
    IBOutlet UILabel *headingLabel;
}
@end

If anybody has any tips or links to other similar posts, I would appreciate it!

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文