3

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.

Community
  • 1
  • 1
thekmc
  • 516
  • 5
  • 14
  • 1
    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 Jul 04 '11 at 17:33
  • 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 Jul 04 '11 at 17:44
  • 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 Jul 05 '11 at 05:24
  • 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 Jul 05 '11 at 12:49
  • 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 Jul 06 '11 at 21:29

2 Answers2

1

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.

adam.wulf
  • 2,149
  • 20
  • 27
  • 4
    For future googlers, I thought I'd add that I had a problem of my IBActions not being called. It was caused by my entire view controller being nil, since I had not stored it in a property after passing it on to `window.beginSheet`. – August Lilleaas Aug 04 '18 at 22:12
  • I can indeed confirm @AugustLilleaas suggestion above fixed the issue for me too! Thanks! – cdf1982 Apr 02 '19 at 04:11
  • 1
    Thanks @August Lilleaas .. This was the solution for me! – Ahmed M. Hassan Mar 27 '21 at 09:52
1

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.

Jakob W
  • 3,347
  • 19
  • 27
  • Except it's a mac app, so no simulator. That's okay, I've started the whole project fresh anyway. It was in need of a major rewrite. – thekmc Oct 09 '11 at 02:07