1

这段代码有快捷方式吗?

-(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;
}
4

2 回答 2

1

肯定有办法做到这一点:) 这真的取决于你如何创建和存储你的按钮。您可以将它们存储在数组中并在循环中处理它们:

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

您还可以tag在创建 UIButton 时为其分配唯一属性(此属性UIView在其所有子类中定义并可用)。这样您就不需要单独存储按钮,还可以将它们隐藏在循环中:

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; 
于 2010-02-17T16:53:50.963 回答
0

您还可以使用键值编码

我认为它会是这样的:

for (int i = 1; i <=35; i++)
{
    [self setValue:NO forKey:@"[NSString stringWithFormat:@"button%d", i]];
}
于 2010-02-17T17:04:44.257 回答