I have a parent UIView
and an UITextView
as one of the subviews.
And I created a button to dismiss the parent UIView
like 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 that the parent UIView
didn't get released because if I typed some text into the UITextView
and dismissed it, when I opened the UIView
again, instead of a blank UITextView
, the SAME text is in it again.
I checked the Leaks
tool but I didn't see any leaking. So I'm guessing if I have some kind of retain cycle or what.
UPDATE:I have another object (which is the AppDelegate
) who is holding the UIView
's instance: _myView
as a global variable like 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 to avoid retain cycle, should I create a weak self like this: __weak MyView *weakSelf
and in the animation block do this: [weakSelf removeFromSuperview]
?