3

A seemingly very basic problem, but it's frustrating me to no end and stalling progress. When I click and drag from a UIButton or UIStepper onto the View Controller, the option to add IBAction connections aren't listed.

The View Controller is called BuyNowVC and in my BuyNowVC.h I have:

@interface BuyNowVC : UIViewController {
    IBOutlet UIButton *buyButton;
    IBOutlet UIStepper *myStepper;
}

@property (nonatomic, retain) IBOutlet UIButton *buyButton;
@property (nonatomic, retain) IBOutlet UIStepper *myStepper;

- (IBAction)buttonPressed;
- (IBAction)stepperPressed;

And in BuyNowVC.m:

@synthesize buyButton;
@synthesize myStepper;

- (IBAction)buttonPressed {
    NSLog(@"Button pressed!");
}

- (IBAction)stepperPressed {
    NSLog(@"Stepper pressed!");
}

I'm definitely ctrl dragging onto the View Controller itself but the only options I get with both UIButton and UIStepper are Action Segue: push, modal, custom. No sign of buttonPressed or stepperPressed.

Edit

I should also mention that this isn't the root VC and the UIButton is currently tied to a Segue to the next View Controller (so I can navigate my mockup) but it doesn't seem to make a difference if I remove it.

Sebastian
  • 3,548
  • 18
  • 60
  • 95

3 Answers3

4

First, should BuyNow.m be BuyNowVC.m?

Second, if you are trying to tie an UIButton to an IBAction within your view controller and if that doesn't work, you might have missed re-naming the "Custom Class" field with the name of the view controller you try to connect the UIButton to in storyboard.

Third, you mentioned ".... are Action Segue: push, modal, custom. No sign of buttonPressed or stepperPressed.". This information tells me that you are trying to control drag your UIButton onto another view controller, onto which you try to tie the IBAction there - that is not possible.

Adding Screenshot:

enter image description here

Please check here in storyboard:

You have changed the "Custom Class" name for the UIButton to your own button name.

Please change it back to UIButton as name for "Custom Class" Field.

See ScreenShot:

Don't do this like in the image. Change it back to UIButton. Once you have done so, you will see "Action Connection" waving "Hi" at you again upon control-Dragging to it.

Steps:

1.) Click on your UIButton on your view controller in storyboard.

2.) Check the right-hand side panel (3rd tab from left) and change the "Custom Class" Field back to UIButton.

enter image description here

So it should be:

enter image description here

Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • First: apologies, that was a mistake in the question - have edited it. Second: checked, and the custom class is `BuyNowVC`. Third: No, I'm ctrl dragging into the `UIButton`'s own View Controller and it gives me those options. – Sebastian Feb 06 '14 at 12:37
  • Here's how it shows for me if I ctrl drag from the `UIButton` in Storyboard to `.h` http://i.imgur.com/KyurmXC.png – Sebastian Feb 06 '14 at 12:58
  • @Sebastian Pleasure. I learnt something as well. Your image gave me a clue. – Unheilig Feb 06 '14 at 13:18
1

It is how I normally do it

It is how I normally do it:

While the storyboard is open,

1) Select the middle icon ('Assistant')

2) Unselect the right pane

3) Drag from the button to the ViewController editor while holding the control key. You will notice a small cocentric circle at line 10.

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
1

Following on from the other answer... dragging into the @interface section of code gives you an outlet. Drag into the @implementation section to get an action.

Sorry I can't post the screen print. Not enough 'reputation' :(

Andy L.
  • 63
  • 3