基本UILabel的奇怪键值编码错误

时间:2011-07-26 19:11:03

标签: objective-c

这是一个新的。我正在测试我的各种viewcontrollers是否被我的标签栏加载,所以我把它放在其中一个上面:

- (void)viewDidLoad
{
[super viewDidLoad];
UILabel*yo=[[UILabel alloc] init];
self.testlabel=yo;
self.testlabel.text=[NSString stringWithFormat:@"sup"];

[yo release];

这是我点击该控制器的标签按钮时得到的结果:

2011-07-26 14:05:37.773选择器[802:707] 由于未捕获的异常'NSUnknownKeyException'而终止应用,原因:'[ setValue:forUndefinedKey:]:此类不是键测试标签的键值编码兼容。' *

世界上有什么?!我必须在这里做一些特别基本和错误的事情。有谁能发现它?

我在.h和.m中有这个:

@interface SingleVC : UIViewController

@property (nonatomic, retain) IBOutlet UILabel*testlabel;

@end

@implementation SingleVC

@synthesize testlabel;

我收到以下堆栈错误(我不知道如何阅读):

*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dc25a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f16313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dc24e1 -[NSException raise] + 17
    3   Foundation                          0x00794677 _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x007945e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x0021030c -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x00d388cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x0020ed23 -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x00210ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x000c6628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    10  UIKit                               0x000c4134 -[UIViewController loadView] + 120
    11  UIKit                               0x000c400e -[UIViewController view] + 56
    12  UIKit                               0x000d6f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
    13  UIKit                               0x000d5aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
    14  UIKit                               0x000d78a2 -[UITabBarController _setSelectedViewController:] + 263
    15  UIKit                               0x000d7711 -[UITabBarController _tabBarItemClicked:] + 352
    16  UIKit                               0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
    17  UIKit                               0x00216ce6 -[UITabBar _sendAction:withEvent:] + 422
    18  UIKit                               0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
    19  UIKit                               0x000a4799 -[UIControl sendAction:to:forEvent:] + 67
    20  UIKit                               0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    21  UIKit                               0x000a4750 -[UIControl sendActionsForControlEvents:] + 49
    22  UIKit                               0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
    23  UIKit                               0x000a4799 -[UIControl sendAction:to:forEvent:] + 67
    24  UIKit                               0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    25  UIKit                               0x000a57d8 -[UIControl touchesEnded:withEvent:] + 458
    26  UIKit                               0x00038ded -[UIWindow _sendTouchesForEvent:] + 567
    27  UIKit                               0x00019c37 -[UIApplication sendEvent:] + 447
    28  UIKit                               0x0001ef2e _UIApplicationHandleEvent + 7576
    29  GraphicsServices                    0x00ffb992 PurpleEventCallback + 1550
    30  CoreFoundation                      0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    31  CoreFoundation                      0x00d03cf7 __CFRunLoopDoSource1 + 215
    32  CoreFoundation                      0x00d00f83 __CFRunLoopRun + 979
    33  CoreFoundation                      0x00d00840 CFRunLoopRunSpecific + 208
    34  CoreFoundation                      0x00d00761 CFRunLoopRunInMode + 97
    35  GraphicsServices                    0x00ffa1c4 GSEventRunModal + 217
    36  GraphicsServices                    0x00ffa289 GSEventRun + 115
    37  UIKit                               0x00022c93 UIApplicationMain + 1160
    38  Pickers                             0x000025c9 main + 121
    39  Pickers                             0x00002545 start + 53
)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c
kill
quit

2 个答案:

答案 0 :(得分:1)

因此,在其他网站上进行了一些谷歌搜索后,发现很多人都有这个完全相同和基本的问题。我在这里找到了解决方案:

https://discussions.apple.com/thread/1598422?threadID=1598422

我在每个控制器的各个nib中检查我的类,但是你也必须在每个项目的标签控制器中设置类(我已经为每个标签栏项设置了nib名称,但不是类)。

所以,问题解决了,并且正如预期的那样,非常基本。

但是,为什么创建的错误是用于键值编码,这是一个难题。

答案 1 :(得分:0)

可能是IB中某个对象的连接,以前有一个名为testlabel的IBOutlet?

在ObjC Exceptions中停止调试器,如果不明显,则发布堆栈跟踪