Creando botones haciendo un bucle a través de una matriz
Así que hice esta pregunta antes, y obtuve algunas respuestas, pero las cosas se pusieron muy complicadas, así que decidí volver a preguntar aquí.
Estoy inicializando un scrollview aquí:
ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)];
ScrollView.showsVerticalScrollIndicator=YES;
ScrollView.scrollEnabled=YES;
ScrollView.bounces = YES;
ScrollView.userInteractionEnabled=YES;
[self.view addSubview:ScrollView];
ScrollView.contentSize = CGSizeMake(10500,480);
[self.view addSubview:homeButton];
Tengo matrices para 44 botones que se crearán, las matrices contienen información sobre los nombres, los nombres de archivo de las imágenes, las coordenadas, etc.
Estoy ejecutando esto:
for (int i = 0; i < 44; i++) {
[self makeLabelsAndButtons:i];
xPresCoord += 10;
}
En mi vistaDidLoad
Y este es el método makeLabelsAndButtons:
-(void)makeLabelsAndButtons:(NSInteger)indexPath{
Button = [UIButton buttonWithType:UIButtonTypeCustom];
[Button addTarget:self action:@selector(presPressed:) forControlEvents:UIControlEventTouchUpInside];
Button.frame = CGRectMake(160.0, 240.0, 220.0, [[numbers objectAtIndex:indexPath] integerValue]);
Button.center = CGPointMake(xPresCoord, 200.0);
[Button setBackgroundImage:[UIImage imageNamed:[picArray objectAtIndex:indexPath]] forState: UIControlStateNormal];
[self.ScrollView addSubview:Button];
Label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 32)];
Label.text = [nameArray objectAtIndex:indexPath];
Label.center = CGPointMake([[numbers objectAtIndex:indexPath] integerValue], 390);
[Label setFont:[UIFont fontWithName:@"GurmukhiMN" size:27]];
Label.numberOfLines = 1;
Label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5f];
[Label sizeToFit];
Label.textColor= [UIColor whiteColor];
[ScrollView addSubview:Label];
//[ScrollView insertSubview:Label atIndex:1];
//NSLog(@"name: %@, pic:%@, picY:%i", nameString, picString, picNumb);
for (UIView *subview in ScrollView.subviews) NSLog(@"View: %@", subview);
}
El último NSLOG muestra que las subvistas (etiquetas y botones) no se están agregando, pero no tengo idea de por qué.
Botón y etiqueta se definen como:
UIButton *Button;
UILabel *Label;
En mi archivo .h
Cualquier ayuda es apreciada!
EDITAR: Aquí está el enlace a la otra pregunta