if (peices[1] == 0) { [(hello.value) setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal]; }
}
I have "(hello.value)" in the place i want to have a UIButton name but instead I would like it to read the value of the string as the name of the UIButton, and then it would obviously set the picture of the button to nil.
When you same button "name", do you mean title (i.e. the text it displays)? And are you trying to identify which button based on what the title is? Assuming the answer to both is yes, I think this might do the trick:
[code]]
for (UIButton *button in yourView.subviews) {
if (button.titleLabel.text == hello) {
[button setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal];
}
[/CODE
When you same button "name", do you mean title (i.e. the text it displays)? And are you trying to identify which button based on what the title is? Assuming the answer to both is yes, I think this might do the trick:
[code]]
for (UIButton *button in yourView.subviews) {
if (button.titleLabel.text == hello) {
[button setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal];
}
[/CODE
Good luck,
Cheers
Actually thats not exactly what i needed...
You see how you have declared your UIButton as "button". Instead of directly having typed in "button" i would like to set the name of the button as the value of a string. I have like 50 buttons on a view and it would be easy to set the image of all of them by just changing the number on the button and then changing the image. Like - button1, button2, button3... etc just save button as a string and then add numbers on to the end to set the pictures.
OK - I get you now, you mean that the variable name is given by the string hello. No idea. Here are a few suggestions in case you're stuck.
It would be much easier to add all the buttons programmatically and just run through the array. Or, if you added them through IB, you could run through the subviews array. ORr, you could enter a value for each button in the "tag" field in the IB Inspector and then search the array for that tag.
Anyway - good luck. And, if you find a way to do this please post it here.
Quote:
Originally Posted by BAR115
Actually thats not exactly what i needed...
You see how you have declared your UIButton as "button". Instead of directly having typed in "button" i would like to set the name of the button as the value of a string. I have like 50 buttons on a view and it would be easy to set the image of all of them by just changing the number on the button and then changing the image. Like - button1, button2, button3... etc just save button as a string and then add numbers on to the end to set the pictures.
I'm trying to follow this, and my interpretation is that you want to access the variable with the same name as an NSString. Fortunately, all views conform to KVC (key-value coding). Therefore, you can simply call