0

I have a view with 10 buttons each named Q1, Q2... Q10.

In another method I want to change the background image on the buttons however I am creating the button names from a string as such:

NSString *Q = [NSString stringWithFormat:@"Q%d", i];

i is a integer which changes, is there any way I can access the UIButtons using the string Q so that I can then change the background image.

4

1 回答 1

0

我设法通过创建一个标签数组来找到这个问题的解决方案,如下所示:

NSMutableArray *buttons = [NSMutableArray arrayWithObjects: Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, nil];

然后通过索引访问数组中的按钮:

[[buttons objectAtIndex:i] setBackgroundImage:image forState:UIControlStateNormal];
于 2013-01-22T02:01:47.283 回答