View and Unknown Exception

2019-08-09 07:29发布

问题:

I'm having an strange exception when I go to connect the button in interface builder. Any ideas on what is going on.

2011-04-11 14:14:06.251 LittleTipperPro[1419:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x19b400> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key numberOne.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x3697464f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x3101bc5d objc_exception_throw + 24
    2   CoreFoundation                      0x369743cd -[NSException dealloc] + 0
    3   Foundation                          0x35323edb -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
    4   Foundation                          0x352dc9cb _NSSetUsingKeyValueSetter + 90
    5   Foundation                          0x352dc217 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
    6   Foundation                          0x352be42f -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
    7   UIKit                               0x367218df -[UIRuntimeOutletConnection connect] + 66
    8   CoreFoundation                      0x3690cd7b -[NSObject(NSObject) performSelector:] + 18
    9   CoreFoundation                      0x3690c99d -[NSArray makeObjectsPerformSelector:] + 388
    10  UIKit                               0x36720847 -[UINib instantiateWithOwner:options:] + 586
    11  UIKit                               0x36721e09 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
    12  UIKit                               0x3669b5e9 -[UIViewController _loadViewFromNibNamed:bundle:] + 36
    13  UIKit                               0x36668fa5 -[UIViewController loadView] + 80
    14  UIKit                               0x3654debf -[UIViewController view] + 30
    15  UIKit                               0x3654c2b5 -[UIWindow addRootViewControllerViewIfPossible] + 32
    16  UIKit                               0x3667753f -[UIWindow setRootViewController:] + 166
    17  LittleTipperPro                     0x0000226f -[switchViewsAppDelegate application:didFinishLaunchingWithOptions:] + 178
    18  UIKit                               0x3654c821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
    19  UIKit                               0x36546b65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
    20  UIKit                               0x3651b7d7 -[UIApplication handleEvent:withNewEvent:] + 1114
    21  UIKit                               0x3651b215 -[UIApplication sendEvent:] + 44
    22  UIKit                               0x3651ac53 _UIApplicationHandleEvent + 5090
    23  GraphicsServices                    0x362fee77 PurpleEventCallback + 666
    24  CoreFoundation                      0x3694ba97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    25  CoreFoundation                      0x3694d83f __CFRunLoopDoSource1 + 166
    26  CoreFoundation                      0x3694e60d __CFRunLoopRun + 520
    27  CoreFoundation                      0x368deec3 CFRunLoopRunSpecific + 230
    28  CoreFoundation                      0x368dedcb CFRunLoopRunInMode + 58
    29  UIKit                               0x36545d49 -[UIApplication _run] + 372
    30  UIKit                               0x36543807 UIApplicationMain + 670
    31  LittleTipperPro                     0x0000217b main + 82
    32  LittleTipperPro                     0x00002124 start + 40
)
terminate called after throwing an instance of 'NSException'
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
(gdb) 

Here is the app delegate.m:

#import "switchViewsAppDelegate.h"

@implementation switchViewsAppDelegate


@synthesize window=_window;
@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //IF USER WANTS THIS ONE, THEN LOAD
    viewController = [[UIViewController alloc] initWithNibName:@"viewTwo" bundle:nil];

    //[self.window addSubview:viewController.view];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

@end

Here is the delegate.h:

#import <UIKit/UIKit.h>

@interface switchViewsAppDelegate : NSObject <UIApplicationDelegate> {

    UIViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIViewController *viewController;

@end

Any help or suggestions, really appreciated!

  • Note: I have a view called viewTwo with a nib, and I don't have a nib for the view controller, and then I have a mainWindowNib.

回答1:

You are allocating a UIViewController directly as viewTwo. If the viewTwo nib has any kind of outlets set up other than view, which I am sure it does, then you will get a crash. Change your code to match your implementation file for nib.

Ex.

#import "viewTwo.h"

...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //IF USER WANTS THIS ONE, THEN LOAD
    viewController = [[viewTwo alloc] initWithNibName:@"viewTwo" bundle:nil];


回答2:

I was getting this error because I started to link a TextView up, and then stopped, Click on the view its giving you problems with, and look at all the outlets and actions in the right toolbar. I found one in mine with an x on it. after deleting the connection all is well.



回答3:

Look in your NIB files and check each object's outlet connections for one that points to numberOne. A connection might be still present in your nib even if the object "numberOne" has been removed from Interface Builder. In that case you'll still see the outlet connection, but it will be grayed-out. Just remove it and save your NIB.