in my .h I have
IBOutlet NSMutableArray *buttons;
@property (nonatomic, retain) IBOutletCollection(UIButton) NSMutableArray *buttons;
-(void)play:(UIButton *)theButton;
in my .m I have
-(void)initButtons{
buttons = [[NSMutableArray alloc] initWithCapacity:1];
UIButton *myBut = [UIButton alloc];
[buttons addObject: myBut];
[[buttons objectAtIndex:0] addtarget:self action@selector(play:) forControlEventTouchUpInside];
}
…
-(void)dealloc{
[buttons dealloc];
[super deallloc];
}
…..
-(void)viewDidLoad{
[super viewDidLoad];
[self initButtons];
}
I dragged the buttons IBoutletCollection in interface builder to a simple button, but when I test it it doesn’t perform the expected action;
I should mention that if I turn my action into (IBAction) instead of (void) and link it to the button it works;
I don’t understand very well NSArrays and outlet collections.
The array is set for you with whatever buttons you’ve connected to the collection in the NIB. It fails to do anything because you’ve reset the ivar here:
…or because you’ve not connected buttons to the collection.