Reputation: 381
Cocoa/Objective-C newbie here.
I have a MainMenu.xib file which has a NSView
.
This is what awakeFromNib
in AppDelegate.h looks like :
- (void)awakeFromNib {
NSViewController *x = [[Login alloc] initWithNibName:@"Login" bundle:nil];
NSView *v = [x view];
[_theView addSubview:v];
}
The new view has a button but when I click on it, I get the message "unrecognized selector sent to instance".
I'm completely lost. Please help me with this. Thanks!
It also throws as "Thread 1: EXC_BAD_ACCESS (code = 1, address = ...) at the line (in main.m):
return NSApplicationMain(argc, argv);
The error is :
2014-10-14 09:05:09.743 FAST Tax Scanner[18408:303] -[OS_dispatch_queue_runloop login:]: unrecognized selector sent to instance 0x6000000f7900 2014-10-14 09:05:09.743 FAST Tax Scanner[18408:303] -[OS_dispatch_queue_runloop login:]: unrecognized selector sent to instance 0x6000000f7900 2014-10-14 09:05:09.744 FAST Tax Scanner[18408:303] ( 0 CoreFoundation 0x00007fff9484725c exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff8c72fe75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff9484a12d -[NSObject(NSObject) doesNotRecognizeSelector:] + 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 trackMouse:inRect:ofView:untilMouseUp:] + 2316 9 AppKit 0x00007fff8b8e2a27 -[NSButtonCell trackMouse: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 run] + 646 14 AppKit 0x00007fff8b63d783 NSApplicationMain + 940 15 FAST Tax Scanner 0x0000000100001452 main + 34 16 libdyld.dylib 0x00007fff982c55fd start + 1 17 ??? 0x0000000000000003 0x0 + 3 )
Upvotes: 0
Views: 1145
Reputation: 31026
Oh, I see....
Try saving NSViewController *x
as a strong property of the object that creates it instead of having it as a local variable. The way it's currently created, the Login
object will not survive past the end of the awakeFromNib
method.
Upvotes: 1