查看和未知异常

Posted

技术标签:

【中文标题】查看和未知异常【英文标题】:View and Unknown Exception 【发布时间】:2011-04-11 18:18:25 【问题描述】:

当我去连接界面生成器中的按钮时,我遇到了一个奇怪的异常。对正在发生的事情有任何想法。

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) 

这是应用程序 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

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

注意:我有一个名为 viewTwo 的视图,带有一个 nib,我没有用于视图控制器的 nib,然后我有一个 mainWindowNib。

【问题讨论】:

我敢打赌你的笔尖有问题...... 我检查了笔尖里面的所有东西,我应该看什么? Something 名为“numberOne”.. 表示它正在尝试设置属性“numberOne”,而普通UIViewController 不存在该属性 我有两个视图笔尖,但我没有视图控制器的笔尖,是吗? 我不知道。奇怪的问题:viewTwo.nib 文件是否使用自定义视图?如果是这样,您需要将[UIViewController alloc] 更改为[TheNameOfMyCustomView alloc] 【参考方案1】:

您将UIViewController 直接分配为viewTwo。如果 viewTwo nib 设置了除 view 之外的任何类型的插座,我相信确实如此,那么你会崩溃。更改代码以匹配 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];

【讨论】:

非常感谢,这正是问题所在。【参考方案2】:

我收到此错误是因为我开始链接 TextView,然后停止,单击它给您带来问题的视图,然后查看右侧工具栏中的所有出口和操作。我在我的身上找到了一个,上面有一个 x。删除连接后一切正常。

【讨论】:

【参考方案3】:

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

【讨论】:

以上是关于查看和未知异常的主要内容,如果未能解决你的问题,请参考以下文章

应用程序发生异常 未知的软件异常(0x0eedfade),位置为0x7c812afb 怎么解决

未知异常和崩溃

CTime未知异常c ++

异常尝试保存更改时“X”的值未知

捕获未知异常

Smarty:如何修复“未知修饰符'rewrite'”异常?