0

I have linked a set of buttons to and IBOutletCollection NSMutableArray; I want to be able to make each button play a specific sound; However after linking them I realised they were not added in any particular order. I think the interface builder doesn't take into account the order of the added buttons. Is there any way I could possibly access the interface button id through code and cast it as an integer so I could programatically assign the right sound to the right button?

Don't think is necessary but here is my code:

for(int i=0;i<48;i++){
UIButton *Pad=[UIButton alloc];
[Pads addobject:Pad];
[Pad release];
[[Pads objectAtindex:i] addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
((UIButton*)[Pads objectAtIndex:i]).tag=i;
} 

To be more specific. In the interface builder in the atributes inspector each button has a label and an id. Would it be possible to reorder my array programatically using that id(or label for that matter)?

FIXE by sorting by TITLE [button currentTitle]

Vlad Otrocol
  • 2,952
  • 7
  • 33
  • 55

2 Answers2

3

Simply set the tag property of each IBOutlet to i when adding it to Pads.

Keller
  • 17,051
  • 8
  • 55
  • 72
2

IBOutletCollection do not support ordering. Here's a similar question with an answer which orders collection contents by their position: IBOutletCollection set ordering in Interface Builder

Community
  • 1
  • 1
Josh Rosen
  • 1,686
  • 1
  • 12
  • 17