ios - Sending removeFromSuperview to self didn't release itself in my scenario -
i have parent uiview , uitextview 1 of subviews. , created button dismiss parent uiview this:
-(void)cancelbuttonpressed:(uibutton *)sender { [uiview animatewithduration:0.2 delay:0.0 options:uiviewanimationoptioncurveeaseinout animations:^{ self.frame = cgrectzero; } completion:^(bool finished) { if (finished) { [self removefromsuperview]; } }]; } i can tell parent uiview didn't released because if typed text uitextview , dismissed it, when opened uiview again, instead of blank uitextview, same text in again.
i checked leaks tool didn't see leaking. i'm guessing if have kind of retain cycle or what.
update:i have object (which appdelegate) holding uiview's instance: _myview global variable this:
_myview = [[myview alloc] init]; _myview.namelabel.text = _user.screen_name; [_window addsubview:_myview]; [uiview animatewithduration:0.2 delay:0.0 options:uiviewanimationoptioncurveeaseinout animations:^{ _myview.frame = cgrectzero; } completion:nil]; but in order avoid retain cycle, should create weak self this: __weak myview *weakself , in animation block this: [weakself removefromsuperview]?
i've tried calling removefromsuperview on view itself, , doesn't result in view being released.
if want release view, go approach uses delegate. way, able call removefromsuperview on view, once animation complete, , set nil. has worked me in past.
so, can add method view class want animate closed, animation. set view controller delegate view, , call method on delegate, completion block of animation.
you can create own protocol this. if keep general enough, , focus on animation callbacks, can reuse protocol in view controllers.
Comments
Post a Comment