3
votes

Okay, so I'm writing an application in Xcode (version 3) for Mac OS X and I'm having trouble with my IBactions. I write them, and connect them to my buttons, but for some reason, they are never called when I click the button. I have double checked and triple checked the connections in Interface builder, but no luck. If you can't help with this, then maybe somebody knows how to manually connect actions to buttons in code? I have found Can you hard code IBActions and IBOutlets, rather than drag them manually in Interface Builder?, but that is for iphone, and what it suggests didn't seem to be in Mac OS X cocoa, only cocoa touch (Not sure though). If anybody could help, I would greatly appreciate it.

UPDATE: I can confirm that this problem is only in one project. New projects work fine.

2
How are you checking that they aren't called? Can you create a minimal case that exhibits the problem, or is it just three random buttons?Chuck
They aren't being called, because I put an NSLog in the method, and there isn't any log message. I think if I made a new project, the problem would be gone, but I would like it if I didn't have to go through the trouble. So, in other words, I think it's this project only.thekmc
Maybe the XIB file you're editing isn't the same one that's running. Try doing something like adding an extra button and then building and running and see if the button is there. If not, check that your XIB file is a member of your application target.Jon Hess
No dice. I added a button, and it was there when I built it. It feels more like a bug in Xcode or IB than anything.thekmc
I managed to hack my buttons to work, by adding their code to another IBAction, which was working. I wouldn't consider that an answer, but just to tell you I at least have it working now.thekmc

2 Answers

1
votes

Have you tried uninstalling your app from simulator/device and do a fresh build and run? I had the same problem and that did the trick for me.

1
votes

I was running into this same problem and hoped this post had the answer. After some more testing, it seems to do with the signature of the IBAction.

This signature didn't work:

-(IBAction)myAction;

This signature did work:

-(IBAction)myAction:(id)sender;

Adding in the sender parameter seems to do the trick.