这段代码有快捷方式吗?
-(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;
}
答案 0 :(得分:1)
肯定必须有办法:)这实际上取决于你如何创建和存储你的按钮。您可以将它们存储在数组中并循环处理它们:
for (UIButton* button in buttonsArray)
button.hidden = NO;
您还可以在创建UIButton时为其分配唯一的tag
属性(此属性在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;
答案 1 :(得分:0)
您也可以使用Key Value Coding
我认为会是这样的:
for (int i = 1; i <=35; i++)
{
[self setValue:NO forKey:@"[NSString stringWithFormat:@"button%d", i]];
}