2
votes

I've been fiddling with Objective-C + Cocoa and writing a fairly simple Cocoa application. Then I encountered a runtime error that has no effect on my program execution:

Could not connect the action textField: to target of class BarController

I'm experimenting with pulling some of the windows out of MainMenu.xib and loading them with separate controllers and xib files.

In one window within a new xib I've created a Text Field and linked it to an IBOutlet NSTextField (textField) in a new NSWindowController subclass. It works and I am able to use textField to update the contents of the Text Field.

I am curious why I am getting the above runtime error and I'm hoping that understanding it will clear up some of the magic around the UI construction process.

1

1 Answers

0
votes

Not much magic with plain IBOutlets, really - the fun starts when using Bindings or actions sent to some yet unknown target via First Responder and the responder chain :-)

Regarding your error:
Sounds like you've connected an outlet to a target that doesn't exist in your target class?

You might have established a connection to a property in File Owner (or some other proxy object) at some point where the owner's class was e.g. MyAppDelegate.
Then you've moved the window (or other object containing the outlet) to some other .xib and now the owner's class is MyWindowController that doesn't have a property of the same name you've connected your outlet to - and voila, the runtime won't be able to establish the connection for your outlet at runtime.

Just double-check your outlets in the Interface Editor, there's probably already some kind of warning message displayed next to outlets that look fishy.

Delete or reassign them and you're done.