0

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 IBActions 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?

Community
  • 1
  • 1
Evan Dyson
  • 195
  • 1
  • 14

2 Answers2

1

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];
}
NSGod
  • 22,699
  • 3
  • 58
  • 66
  • This sounds promising... On first attempt there was a linker error. Working to resolve. – Evan Dyson Sep 07 '12 at 15:14
  • This is the error I'm still receiving... Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_InputViewController", referenced from: objc-class-ref in ReportController.old: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) – Evan Dyson Sep 07 '12 at 16:35
  • Resolved linker issue (ReportController.m wasn't listed in target compile list) but still receiving error after updating to your recommendation: Could not connect the action testButton: to target of class InputViewController – Evan Dyson Sep 07 '12 at 16:49
0

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!

Liftoff
  • 24,717
  • 13
  • 66
  • 119