user1913674
user1913674

Reputation: 85

Control more than one button using tags

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 for loop but I couldn't do it how can I solve this problem?

(IBAction)btnAction:(id)sender{

UIButton *btnPressed = (UIButton *)sender;

NSUInteger i=btnPressed.tag;

for(i=0; i<29; i++)
{
    btnPressed.hidden=NO;

}

}

Upvotes: 0

Views: 78

Answers (3)

SAMIR RATHOD
SAMIR RATHOD

Reputation: 3510

use IBOutletCollection. see the following link for your answer.

IBOutletCollection and

IBOutletCollection (UIbutton)

IBOutletCollection of UIButtons - changing selected state of buttons

Upvotes: 0

Deepesh Gairola
Deepesh Gairola

Reputation: 1242

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 //
  }

Upvotes: 0

matt
matt

Reputation: 535168

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.

Upvotes: 8

Related Questions