可可/ Objective-C新手在这里。

我有一个具有NSView的MainMenu.xib文件。
这是AppDelegate.h中的awakeFromNib看起来像:

- (void)awakeFromNib {
NSViewController *x = [[Login alloc] initWithNibName:@"Login" bundle:nil];
NSView *v = [x view];
[_theView addSubview:v];


}

新视图有一个按钮,但是当我单击它时,收到消息“无法识别的选择器发送到实例”。

我完全迷路了。请帮我解决一下这个。谢谢!

它还在行(在main.m中)中抛出“线程1:EXC_BAD_ACCESS(代码= 1,地址= ...):

return NSApplicationMain(argc, argv);


错误是:

2014-10-14 09:05:09.743 FAST Tax Scanner [18408:303]-[OS_dispatch_queue_runloop登录:]:无法识别的选择器已发送到实例0x6000000f7900
2014-10-14 09:05:09.743 FAST Tax Scanner [18408:303]-[OS_dispatch_queue_runloop登录:]:无法识别的选择器已发送到实例0x6000000f7900
2014-10-14 09:05:09.744 FAST Tax Scanner [18408:303](
    0 CoreFoundation 0x00007fff9484725c异常预处理+ 172
    1个libobjc.A.dylib 0x00007fff8c72fe75 objc_exception_throw + 43
    2 CoreFoundation 0x00007fff9484a12d-[NSObject(NSObject)didNotRecognizeSelector:] + 205
    3 CoreFoundation 0x00007fff947a5272 ___forwarding_ + 1010
    4 CoreFoundation 0x00007fff947a4df8 _CF_forwarding_prep_0 + 120
    5 AppKit 0x00007fff8b87d260-[NSApplication sendAction:to:from:] + 327
    6 AppKit 0x00007fff8b87d0de-[NSControl sendAction:to:] + 86
    7 AppKit 0x00007fff8b8c9c4d-[NSCell _sendActionFrom:] + 128
    8 AppKit 0x00007fff8b8e3655-[NSCell tr​​ackMouse:inRect:ofView:untilMouseUp:] + 2316
    9 AppKit 0x00007fff8b8e2a27-[NSButtonCell tr​​ackMouse:inRect:ofView:untilMouseUp:] + 487
    10 AppKit 0x00007fff8b8e213d-[NSControl mouseDown:] + 706
    11 AppKit 0x00007fff8b863a58-[NSWindow sendEvent:] + 11296
    12 AppKit 0x00007fff8b8025d4-[NSApplication sendEvent:] + 2021
    13 AppKit 0x00007fff8b6529f9-[NSApplication运行] + 646
    14 AppKit 0x00007fff8b63d783 NSApplicationMain + 940
    15 FAST Tax Scanner 0x0000000100001452主+ 34
    16 libdyld.dylib 0x00007fff982c55fd开始+ 1
    17 ??? 0x0000000000000003 0x0 + 3

最佳答案

哦,我明白了....

尝试将NSViewController *x保存为创建它的对象的强属性,而不是将其作为局部变量。当前创建的方式Login对象将无法保存到awakeFromNib方法的末尾。

关于objective-c - 在按钮上单击“无法识别的选择器发送到实例”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26361955/

10-13 01:00