查看和未知例外

时间:2011-04-11 18:18:26

标签: iphone objective-c ios4 iphone-sdk-3.0 interface-builder

当我连接界面构建器中的按钮时,我遇到了一个奇怪的异常。关于发生了什么的任何想法。

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) 

这是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

这是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

任何帮助或建议,非常感谢!

  • 注意:我有一个带有nib的viewTwo视图,我没有视图控制器的笔尖,然后我有一个mainWindowNib。

3 个答案:

答案 0 :(得分:3)

您正在直接分配UIViewController作为viewTwo。如果viewTwo nib有任何类型的出口设置,而不是视图,我相信它确实存在,那么你将会崩溃。更改代码以匹配nib的实现文件。

实施例

#import "viewTwo.h"

...

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

答案 1 :(得分:2)

我收到此错误是因为我开始链接TextView,然后停止,单击视图,它会给您带来问题,并查看右侧工具栏中的所有插座和操作。我发现我的一个上面有一个x。删除连接后一切都很顺利。

答案 2 :(得分:0)

查看您的NIB文件并检查每个对象的插座连接,以查找指向numberOne的连接。即使已从Interface Builder中删除对象“numberOne”,您的nib中仍可能存在连接。在这种情况下,您仍然会看到插座连接,但它会变灰。只需将其删除并保存您的NIB。