I'm currently using Xcode 4.6 and I'm simply wondering how to select multiple buttons across different UIViews, but under a single view controller. CMD clicking doesn't seem to work. I need this functionality because in Xcode 4.6 the only way to let two buttons on IB to share the same action is to select them at once and then drag the action to your view controller.
My ultimate goal is to get two different buttons on two different UIViews to match the same action using storyboards in Xcode 4.6. Is there a way to do this?
EDIT: I'm currently using Xcode 4.6.1 without any luck, upgrading to 4.6.2.
You can connect multiple buttons to a single action without selecting them all at once.
However, after creating the action, you need to save the source file containing the action before Xcode will let you connect another control to the action.
I did this with Xcode 4.6.2:
Swift 3.0 Xcode 8.0+
Connect all buttons to below method signature.
Make sure argument sender is of type UIButton (Or subclass of UIButton) in-order to connect rest of the buttons from storyboard.
@IBAction func dialconfigTapped(_ sender: UIButton) {}
Use sender.tag to identify the tapped button.
Follow this steps
1. Create IBAction In View Controller
In .h file
-(IBAction)action:(id)sender;
In .m File
-(IBAction)action:(id)sender{
}
2 . Connect all button to this action
3 . Give Each Button a tag by follow the next Picture
4 . Now inside your action function put these
-(IBAction)action:(id)sender{
UIButton *button=(UIButton*)sender;
if(button.tag==1){
//your stuff!
}
if(button.tag==2){
//your stuff!
}
if(button.tag==3){
//your stuff!
}
}
Run and Go.
You should be able to do this in IB. In IB, simply point them at the same IBAction
in the relevant class.
When the action comes, in case you want to know from which button you got the action, you can then differentiate between the buttons within the IBAction
method either by reading the text from the button or using the tag
attribute which you should have set from IB.
- (IBAction)buttonClicked:(id)sender {
NSLog(@"Button pressed: %@", [sender currentTitle]);
NSLog(@"Button pressed: %@", [sender tag]);
}
You can use IBOutletCollection
the following link will help you in using that
http://useyourloaf.com/blog/2011/03/28/interface-builder-outlet-collections.html
In Xcode 5, after setting action for the 1st button, I have to build the app. This then allows me to connect other buttons action to this same IBAction method
in xcode 4.6.3
you no more need to save before assigning action.