4

I am trying to hook up a UIButton to a IBAction in interface builder but IB will not show the method that I defined as an option to hook it up to.

- (IBAction)someAction:(id)sender;

That is what I have in the h file, and then in the M file I have

- (IBAction)someAction:(id)sender{
NSLog(@"Button Tapped.");   }

The IB Document is connected to that class i know because that class also has a UIPicker, and that connects fine.

Any help would be brilliant on this,

Thanks, Callaghan001.

Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
Callaghan001
  • 55
  • 1
  • 6

6 Answers6

4

I fixed this problem by reading in the Class file manually from Interface Builder. Just do File -> Read Class -> find the .h file you defined the IBAction in. -> open! Then Interface builder will say something like "one Class file parsed"

Whopper
  • 41
  • 2
  • This can also reveal IB error messages, which can be useful in tracking down other cases where IB gets confused. – JJ Rohrer Jul 01 '11 at 01:05
3

Make sure you're actually wiring up the handler for the button's event (probably touch up inside) and not the button itself. So instead of dragging directly from the button, either ctrl-click the button to see its connections and drag from its touch up inside event to the target, or ctrl-click the target, find the action, and drag from that to the button. If the action doesn't show up on the target in these cases, and you're sure interface builder knows what class it is, then I'm baffled.

zem
  • 1,257
  • 9
  • 15
  • No I am using the touch up inside option, and it is still not showing up. Its really annoying. I have seen this before once after I updated xcode the last time and eventually it just started working again for no reason, but its just frustrating. – Callaghan001 Sep 15 '10 at 10:16
  • then i'm baffled. aside from the obvious "solutions," like restarting xcode/interface builder, which i assume you've already tried. – zem Sep 15 '10 at 10:20
  • 1
    Just tried a restart and cleared the PRAM of the machine and finally it is working now with no change to the code. The mind boggles as to why it wasn't working in the first place. – Callaghan001 Sep 15 '10 at 10:39
1

try adding -(IBAction)testFunction:(id)sender; in the .h file.

It worked for me.

Luke
  • 11,426
  • 43
  • 60
  • 69
Govind
  • 84
  • 7
1

I had a this problem and restarting Xcode did not solve it.

What solved it for me was:

  1. Select File Owner
  2. Go to Identity Inspector (under Utilities, right hand side panel).
  3. Under Custom Class section, just select the text field (where your custom UIViewController sub-class name should be displayed) and hit 'Enter'.
Nikolay Suvandzhiev
  • 8,465
  • 6
  • 41
  • 47
1

same problem, reading class file in didn't fix it but changing the class name in the controller identity inspector from UIViewController to the correct subclass name did.

user788933
  • 11
  • 1
-2

I think your implementation must be

- (void)someAction:(id)sender
{
    NSLog(@"Button Tapped.");   
}
Luke
  • 11,426
  • 43
  • 60
  • 69
user427179
  • 83
  • 1
  • 6
  • No IBAction will work too, I fixed it with w reset of the PRAM, will keep an eye on it, hopefully it wont keep happening. – Callaghan001 Sep 16 '10 at 12:39