objective c - UIButton Selector Not Called in ARC -
i have 2 classes, view , viewcontroller. view creates button follows:
_button = [[uibutton alloc] initwithframe:cgrectmake(50, 0, buttonimage.size.width, buttonimage.size.height)]; [_button setimage:buttonimage forstate:uicontrolstatenormal]; [_button setimage:[uiimage imagenamed:@"btn_learn_focus_pad"] forstate:uicontroleventtouchupinside]; [_button addtarget:self action:nil forcontrolevents:uicontroleventtouchupinside]; [_someview addsubview:_button]; in viewcontroller, after instantiated view in loadview, add selector follows:
[view.button addtarget:self action:@selector(buttonpressed:) forcontrolevents:uicontroleventtouchupinside]; the selector not being called. tried nslog in viewcontroller button's position , printed out zero. suspect arc releasing button. _button however, strong pointer (@property). not sure why happening.
how around this?
you not utilizing proper getter/setter methods generated property synthesis. if change first line to:
self.button = [[uibutton alloc] initwithframe:cgrectmake(50, 0, buttonimage.size.width, buttonimage.size.height)]; it retain pointer
Comments
Post a Comment