开发者

Bizarre key-value coding error for basic UILabel

This is a new one. I'm testing that my various viewcontrollers are getting loaded by my tab bar, so I put this on one of them:

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

[yo release];

This is what I get when I click the tab button for that controller:

2011-07-26 14:05:37.773 Pickers[802:707] Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testlabel.'*

What in the world?! I must be doing something exceptionally basic and wrong here. Can anyone spot it?

I've got this in the .h and .m:

@interface SingleVC : UIViewController

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

@end

and

@implementation SingleVC

@synthesize testlabel;

I get the following stack errors (which I do not know how to read):

*** 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                               0x000d6f5开发者_高级运维4 -[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


So after some Googling on other sites, it turns out that quite a few people have had this exact same and basic problem. I found the solution here:

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

I was checking my classes within the individual nibs of each controller, but you must also set the classes in the tab controller as well, for each item (I had already set the nib name for each tab bar item, but not the class).

so, problem resolved and was, as expected, quite basic.

It's a stumper why the error created was for key value coding, though.


perhaps a connection in IB from some object that formerly had an IBOutlet called testlabel?

stop the debugger in ObjC Exceptions and post your stack trace if it's not obvious

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜