How to connect multiple buttons in a storyboard to a single action?

后端 未结 7 1085
梦谈多话
梦谈多话 2020-12-03 10:16

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 s

7条回答
  •  鱼传尺愫
    2020-12-03 10:58

    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]);
    }
    

提交回复
热议问题