Reputation: 111
I placed 1 UIButton on nib, and when user click this button,an IBAction method connect to it with a Status param.
What I want is, user click button and pass the Status to the IBAction method, and in that method, I need access the instance of the button.
How can I get the button's instance without an (id) sender here?
Upvotes: 0
Views: 592
Reputation: 47241
You can wire up the UIButton with an outlet like you did with your IBAction to connect it.
In your header add:
UIButton *myButton;
...
@property (nonatomic, retain) IBOutlet UIButton *myButton;
And then link the new outlet with your button in IB.
Then you can access the button with myButton in your instance.
Upvotes: 1
Reputation: 135548
Why without (id) sender
? And what do you mean by that anyway? The sender
argument of the action method is a reference to the button's instance. All you have to do is cast it to the proper type:
UIButton *button = (UIButton *)sender;
Upvotes: 0
Reputation: 26400
- (IBAction)buttonPress:(id)sender
{
UIButton *button = (UIButton *)sender;
// button is the instance of your button
}
Upvotes: 0