Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not connect the action: to target of class NSApplication

I keep getting Could not connect the action startServer: to target of class NSApplication error on compile. I understand what the error is but not sure how to fix it. Somehow my xib is trying to invoke startServer method in NSApplication which doesn't exist.

like image 456
ed1t Avatar asked Jul 19 '11 02:07

ed1t


2 Answers

It sounds as if you connected your UI element to the File's Owner object, which is an instance of NSApplication.

If you haven't done so already, you want to drag a NSObject out of the Object Library palette in Xcode 4 to the margin to the left of your layout. Once you've done that, and have selected it, choose the identity inspector and, in the Class field, enter "WindowController".

Now that you've got a representation of your WindowController, which as you said contains startServer:, then you can connect your UI element to that. Be sure your startServer method is of the form:

- (IBAction)startServer:(id)sender

or you won't be able to make the connection.

Good luck to you in your endeavors.

like image 137
Extra Savoir-Faire Avatar answered Nov 15 '22 16:11

Extra Savoir-Faire


Simply you can fix this by two easy ways:

  1. [[YourWindowController alloc]initWithWindowNibName:XIB_YOUR_WINDOW_CONTROLLER]; here do not create with owner. so NSApplication will not be the owner.

  2. [[YourWindowController alloc]init]; and in YourWindowController.m file override init method and there call self = [super initWithWindowNibName:XIB_YOUR_WINDOW_CONTROLLER];

either 1 or 2 will fix this problem.

Happy Coding....

like image 34
Jayant Dash Avatar answered Nov 15 '22 16:11

Jayant Dash