I have created buttons, each with their own tag.
These tags have already been used in the buttonPushed: method
How do I use the tags in another method? I have searched elsewhere but could not find the answer.
Many thanks,
Tom.
Code:
int tag;
for (int i = 0; i < N_COLS; i++) {
for (int j = 0; j < N_ROWS; j++) {
soundButton = [UIButton buttonWithType:UIButtonTypeCustom];
soundButton.frame = CGRectMake(i * 20.0, j * 20.0, 20.0, 20.0);
tag=j + i * N_ROWS + 1;
soundButton.tag = tag;
buttonStatus[tag] = NO;
[soundButton setImage:[UIImage imageNamed:@"BWhite2.png"]
forState:UIControlStateNormal];
[soundButton addTarget:self action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:soundButton];
}
}
These tags have already been used in the buttonPushed: method
Code:
- (void) buttonPushed:(id)sender {
UIButton *soundbutton = sender;
NSLog(@"buttonPushed tag=%d", soundbutton.tag);
int tag = soundbutton.tag;
buttonStatus[tag] = !buttonStatus[tag];
NSLog(@"Status=%d", buttonStatus[tag]);
if (buttonStatus[tag]==YES) {
[soundbutton setImage:[UIImage imageNamed:@"BBlue.png"]forState:UIControlStateNormal];
}
else {
[soundbutton setImage:[UIImage imageNamed:@"BWhite2.png"]forState:UIControlStateNormal];
}
}
How do I use the tags in another method? I have searched elsewhere but could not find the answer.
Many thanks,
Tom.