Reputation: 195
I am working on my first native mac app after playing with iOS for a while.
I am attempting to launch a window from a menu item, but I suspect I am doing it wrong. Any IBAction
I connect to buttons on this new window returns an error.
Here is what I am doing. From a menu item I launch this:
-(IBAction)displaySAInput:(id)sender{
NSLog(@"Input selected.");
inputSAViewController = [[NSWindowController alloc] initWithWindowNibName:@"InputViewController"];
[inputSAViewController showWindow:self];
This launches the InputViewController
nib that is owned by the InputViewController
class. I set the InputViewController
class to inherit from NSWindowController
.
On InputViewController.m
I have tested IBAction
s such as:
-(IBAction)testButton:(id)sender{
NSLog(@"Data recalled?");
}
I connect this IBAction
to a button through the Interface Builder. All looks okay.
When I build and open the InputViewController
window I receive this error in the console before clicking anything:
Could not connect the action testButton: to target of class NSWindowController
I have searched extensively but my ignorance prevents me from connecting the dots. This thread based on a similar error with NSApplication looks promising, but I don't quite understand what I'd need to make the connections happen related to the NSWindowController
error.
This should be simple. What am I missing?
Upvotes: 0
Views: 189
Reputation: 22948
Your code:
-(IBAction)displaySAInput:(id)sender{
NSLog(@"Input selected.");
inputSAViewController = [[NSWindowController alloc]
initWithWindowNibName:@"InputViewController"];
[inputSAViewController showWindow:self];
}
Notice you are alloc/initing a generic instance of NSWindowController
, not your custom subclass where you've implemented the testButton:
method. I assume you'd likely want that changed to:
-(IBAction)displaySAInput:(id)sender{
NSLog(@"Input selected.");
inputSAViewController = [[InputViewController alloc]
initWithWindowNibName:@"InputViewController"];
[inputSAViewController showWindow:self];
}
Upvotes: 1
Reputation: 25392
Just load the NSWindow before hand and make it invisible and when the IBAction is called, just do the following:
[myWindow setIsVisible:YES];
[myWindow setLevel:NSFloatingWindowLevel];
Yay!
Upvotes: 0