Control more than one button using tags

后端 未结 3 851
闹比i
闹比i 2021-01-26 00:59

I have 28 buttons in my application. I need to control them in a single function. All I want to do is make all the buttons visible. I gave tags to the buttons. I tried it with a

相关标签:
3条回答
  • 2021-01-26 01:33

    use IBOutletCollection. see the following link for your answer.

    IBOutletCollection and

    IBOutletCollection (UIbutton)

    IBOutletCollection of UIButtons - changing selected state of buttons

    0 讨论(0)
  • 2021-01-26 01:38

    Instead of tags, use an IBOutletCollection. So now you have a single NSArray pointing to all of the buttons. Now just cycle through that NSArray.

    0 讨论(0)
  • 2021-01-26 01:52

    You can create a single IBAction method, check tag values and then do what you want to do

    - (IBAction)btnAction:(id)sender{
         UIButton *btnPressed = (UIBUtton *)sender;
    
        // Check button tags and write code accordingly //
      }
    
    0 讨论(0)
提交回复
热议问题