As said in the title, my IBOutletCollection of UIButtons is empty after viewDidLoad. I created a IBOutletCollection of UILabels the same way, and this one is working perfectly. Any idea how this can be fixed, or where i made a mistake?
Here is the Code:
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *lbl_save;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *lbl_cancel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *lbl_edit;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *btn_changeData;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *btn_save;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *btn_cancel;
The buttons are placed in a xib and linked correctly to the corresponding outlets. Just like the labels.
The time i press the one of the Buttons is the first time, i want to access the Buttons in Code.
for (UIButton *btn in _btn_changeData) {
btn.hidden = NO;
btn.userInteractionEnabled = YES;
}
for (UIButton *btn in _btn_save) {
btn.hidden = YES;
btn.userInteractionEnabled = NO;
}
for (UIButton *btn in _btn_cancel) {
btn.hidden = YES;
btn.userInteractionEnabled = NO;
}
for (UILabel *lbl in _lbl_save) {
lbl.hidden = YES;
}
for (UILabel *lbl in _lbl_cancel) {
lbl.hidden = YES;
}
for (UILabel *lbl in _lbl_edit) {
lbl.hidden = NO;
}
That is also where i got the following Exception and realized, that my Button OUtletcollection is empty.
-[UIButton countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa8a8850
I neither overwrite the outletcollection, nor do i change attributes of the buttons. Its just that the labels are there in the collection and the buttons not. And i have no idea why.
Thx in advance for any help.
Mav
First idea that comes to my mind is that the properties are not correctly synthesized. Is _btn_changeData
really the ivar behind btn_changeData
property?
Second idea is something I saw while debugging someone else's code. When outlets are incorrectly connected, for example, if the controller references itself, two controller instances can be create. Obviously only of of them will have the outlets connected. Make sure only of instance is created.
For debugging, implementing the setter by yourself might be a good idea.
Edit:
After rereading, the problem is actually different they you say in your question. The error message -[UIButton countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa8a8850
doesn't mean that _btn_changeData
is an empty array. It means there is a UIButton
instead of an array.
Having said this, you should check if you are not overwriting the data in _btn_changeData
somewhere.