Ocultar los botones / imágenes de acceso directo?
Pregunta
¿Hay un atajo para este código?
-(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;
}
Solución
Hay sin duda debe haber maneras para que :) Realmente depende de cómo crear y almacenar sus botones. Se pueden almacenar en la matriz y procesarlas en un bucle:
for (UIButton* button in buttonsArray)
button.hidden = NO;
También puede asignar una propiedad única tag
a un UIButton cuando se crea ellos (esta propiedad se define en UIView
y disponible en todas sus subclases). De esta manera no es necesario el almacenamiento separado para los botones y también se les puede ocultar en un bucle:
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;
Otros consejos
También es posible usar Clave Valor Codificación
Creo que sería algo como esto:
for (int i = 1; i <=35; i++)
{
[self setValue:NO forKey:@"[NSString stringWithFormat:@"button%d", i]];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow