J'ai besoin de changer les images sur une matrice de UIButtons, et la seule chose que je connaisse pour adresser les boutons, c'est la balise. Mais je ne peux pas trouver un moyen de réellement nous cet identifiant. Les boutons sont créés par programmation pendant viewDidLoad.Comment accéder à un UIButton en utilisant un tag et changer son image?
Voici le code pour créer des boutons:
#define N_ROWS 4
#define N_COLS 3
int N_IMG = 0;
for (int a = 0; a < N_COLS; a++) {
for (int j = 0; j < N_ROWS; j++) {
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(a * 65.0 + 25, j * 65.0 + 15, 10.0, 10.0);
aButton.tag = j + a * N_ROWS + 1;
[aButton setBackgroundColor:[UIColor redColor]];
N_IMG = N_IMG++;
[self.view addSubview:aButton];
number_sorted = 1;
}
}
Voici le code pour définir l'image:
- (IBAction)set_image:(id)sender {
#define N_ROWS 4
#define N_COLS 3
int N_IMG = 0;
for (int a = 0; a < N_COLS; a++) {
for (int j = 0; j < N_ROWS; j++) {
uibutton aButton.tag == (j + a * N_ROWS + 1)
setImage:[UIImage imageNamed:[puzzles objectAtIndex:N_IMG]]
forState:UIControlStateNormal];
N_IMG = N_IMG++;
}
}
}
Voici le code où commence truble: UIButton aButton.tag == (j + a * N_ROWS + 1)
Qui puis-je configurer pour que cela fonctionne?