ed1t
ed1t

Reputation: 8699

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.

Upvotes: 11

Views: 12633

Answers (4)

Jayant Dash
Jayant Dash

Reputation: 91

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....

Upvotes: 3

whiteglider
whiteglider

Reputation: 69

I was having the same issue but finally got it resolved. I am not sure if this will work for you but try this:

(On Interface Builder)

From the Library, drag an NSObject to the your XIB Document window. Disconnect the objects you've connected to File's Owner by connecting them to the NSObject. Rename the NSObject a suiting one. Highlight NSObject, go to the Inspector. Under Class Identity, search for the name of the NSObject you have just renamed. Save!

See if it works for you! It had mine working now! Good luck!

Upvotes: 2

Extra Savoir-Faire
Extra Savoir-Faire

Reputation: 6036

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.

Upvotes: 22

NSResponder
NSResponder

Reputation: 16861

You've made a connection to the file's owner in your main nib, that you probably meant to connect to something else. What class have you implemented -startServer: in?

Upvotes: 0

Related Questions