ios - Loading a view from NIB, IBOutletCollection is nil even though other IBOutlet's are working fine -
i laid out view in nib file, added uiview subclass file owner.
the subclass looks this:
@property (nonatomic, weak) iboutlet uilabel *categorylabel; @property (nonatomic, weak) iboutletcollection(uiimageview) nsarray *images; the properties weak because of this: https://stackoverflow.com/a/7729141/1016515
then wired label , uiimageviews in nib, view file owner.
then, in awakefromnib part of subclass, did this:
[[nsbundle mainbundle] loadnibnamed:@"categorybutton" owner:self options:nil]; nslog(@"label: %@",self.categorylabel); nslog(@"images: %@",self.images); i expected see addresses of categorylabel , images. instead found category label fine , images nil.
this quite puzzling, because declarations images , categorylabel identical. why 1 work , other fail?
i'm putting because didn't find question anywhere, seems pretty easy mistake make if you're used working iboutlets not iboutletcollections.
i made properties weak because that's iboutlets reasons discussed in question.
what neglected realize iboutletcollection instance variable of class, not arbitrary reference view hierarchy. therefore, if weak property nsarray * released because view hierarchy isn't retaining other iboutlet properties.
the fix simple, make property strong:
@property (nonatomic, strong) iboutletcollection(uiimageview) nsarray *images; update: according this answer, iboutlets should strong, unless must weak avoid retain cycle. new, , documentation still says outlets should weak.
Comments
Post a Comment