Reputation: 27
I have two buttons on top of each other in my nib. I need both of them to be pressed when tapped, but only the top button carries out its function. Is there a way for the top button to tell the bottom button to activate when the top one gets pressed. I do not think I can just merge the buttons into one and use one -(IBAction)buttonName function because one button is bigger than the other so I do not always need both to activate when one of them is pressed.
Thanks!
Upvotes: 1
Views: 973
Reputation: 727047
Since one button is larger than the other, I assume that you would like the smaller button to "bring down" the larger button with it, including the change in the visual state. In cases like that you could send your target button a "tap" programmatically, like this:
- (IBAction)largeButtonClick:(id)sender {
}
- (IBAction)smallButtonClick:(id)sender {
// Perform the acton specific to only the small button, then call
[largeButton sendActionsForControlEvents:UIControlEventTouchUpInside];
}
Upvotes: 2
Reputation: 125037
Is there a way for the top button to tell the bottom button to activate when the top one gets pressed.
Not really, but you can have the action for the top button call the action for the bottom button.
Here's one way:
- (IBAction)actionTop:(id)sender
{
NSLog(@"The top button was activated.");
[self actionBottom:self];
}
- (IBAction)actionBottom:(id)sender
{
NSLog(@"The bottom button was activated.");
}
Another way would be to use the same action for both, and figure out what to do based on which button triggered the action:
- (IBAction)action:(id)sender
{
// if the top button was tapped, do this part
if (sender == self.topButton) {
NSLog(@"The top button was activated.");
}
// you want the bottom button to be activated no matter which button was tapped, so
// no need to check here...
NSLog(@"The bottom button was activated.");
}
the bottom button is the whole screen which changes what is displayed. the top button plays a sound, except there are 4 top buttons that plays different sounds
It seems like an invisible button covering the whole screen might be the wrong way to tackle the problem. You might look into using a gesture recognizer attached to your view to trigger the change. Your button actions could call the same method that the gesture recognizer uses.
Upvotes: 3