Question

iOS 7, XCode 5, using Storyboards.

I have a TableViewController. Inside the TVC I have 2 custom cells. One of these cells contains a button "Submit order" created on Storyboards. The button is added then to code as IBAction

I can't figure out how to get a reference to the IBAction button so I can set its 'hidden' property to true.

Any suggestions?

Was it helpful?

Solution

You'll need to set an IBOutlet reference from the TableViewController back to the button. IBAction denotes a message the button will send the target. IBOutlet denotes a reference back to the control itself.

The process is similar to the process you (maybe) used to create the IBAction in the first place. Add a line "@property (nonatomic, weak) IBOutlet UIButton* button;" to your TableViewController.h file. Then in Interface builder, control-drag from the TableViewController to the button and select the outlet from the popup.

FWIW, it's usually bad UI to hide an inactive button, better to just disable it. (enabled = false)

OTHER TIPS

First, you'll need to create a reference to the button in your code, in your TableViewController class:

@property(nonatomic, assign)IBOutlet UIButton * button;

Next you'll want to switch to your nib/xib or storyboard file. On the left side "Placeholders" inner sidebar, ensure that File's Owner is Selected, which in a storyboard is your TableViewController. This switches the context to insure that the the right sidebar is referring the TableViewController.

The last tab on the right sidebar should now have an Entry for button (Or whatever you called the property on your controller.) under the Outlets section. Drag the plus circle icon to your button you're working with. This creates a reference to that button object in your controller. I'm guessing your button is of the class UIButton.

Back in your viewDidLoad method, you can now use that property to change that button.

self.button.alpha = 0;
//Alternative to making the button diappear...
self.button.enabled = NO;

Reference the button in your header file with an outlet, then to disable it's functionality in your code (probably viewDidLoad) use: self.myButton.enabled = NO; Then if you want to make it invisible, use: self.myButton.alpha = 0;

Then just do the reverse of that when you want to use the button again

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top