views:

50

answers:

2

Is there a shortcut for this code?

-(IBAction)reset{
    button1.hidden=NO;
    button2.hidden=NO;
    button3.hidden=NO;
    button4.hidden=NO;
    button5.hidden=NO;
    button6.hidden=NO;
    button7.hidden=NO;
    button8.hidden=NO;
    button9.hidden=NO;
    button10.hidden=NO;
    button11.hidden=NO;
    button12.hidden=NO;
    button13.hidden=NO;
    button14.hidden=NO;
    button15.hidden=NO;
    button16.hidden=NO;
    button17.hidden=NO;
    button18.hidden=NO;
    button19.hidden=NO;
    button20.hidden=NO;
    button21.hidden=NO;
    button22.hidden=NO;
    button23.hidden=NO;
    button24.hidden=NO;
    button25.hidden=NO;
    button26.hidden=NO;
    button27.hidden=NO;
    button28.hidden=NO;
    button29.hidden=NO;
    button30.hidden=NO;
    button31.hidden=NO;
    button32.hidden=NO;
    button33.hidden=NO;
    button34.hidden=NO;
    button35.hidden=NO;
}
+1  A: 

There definitely must be ways for that :) It really depends on how you create and store your buttons. You can store them in array and process them in a loop:

for (UIButton* button in buttonsArray)
   button.hidden = NO;

You can also assign a unique tag property to a UIButton when you create them (this property is defined in UIView and available in all its subclasses). This way you do not need separate storage for buttons and you can also hide them in a loop:

for (int tag = min_tag_value; tag < max_tag_value;++tag)
    // Assume that self.view is a view that contains your buttons
    [self.view viewWithTag:tag].hidden = NO; 
Vladimir
A: 

You could also use Key Value Coding

I think it would be something like this:

for (int i = 1; i <=35; i++)
{
    [self setValue:NO forKey:@"[NSString stringWithFormat:@"button%d", i]];
}
willcodejavaforfood