I have a very simple Mac App built with XCode 4 (just a blank form for now).
Now I’ve added a button via Interface Builder and a method to my AppDelegate:
-(IBAction) btnScanClicked
{
NSLog(@"Hello!");
}
When I start my App I get the following message:
Could not connect the action btnScanClicked: to target of class
AppDelegate
Does that mean I can’t add any event handlers to my AppDelegate? Where else could I put them, and how would I set that up with Interface Builder?
The problem is that you haven’t declared the action method properly. Replace the definition with:
Notice how the error message states that it couldn’t connect to
btnScanClicked:That colon at the end isn’t punctuation – it’s says that the message takes a parameter.Unlike
UIKitaction methods need to be of the form:IBActionjust resolves tovoid, but is an indicator to Interface builder that it is an method that can be hooked up by context dragging.