Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A tip for "dealloc" method never be called #64

Open
tatowilson opened this issue Mar 20, 2019 · 0 comments
Open

A tip for "dealloc" method never be called #64

tatowilson opened this issue Mar 20, 2019 · 0 comments

Comments

@tatowilson
Copy link

First of all, thank yannickl for this awesome project.

We imported the version 3.10.2 into our project, and found that the dealloc method was never called.

I found the _progressTargetTimer may never be invalid if the progress didn't reach the end.

- (void)updateProgressWithTimer:(NSTimer *)timer
{
CGFloat dt_progress = [timer.userInfo floatValue];
_progress += dt_progress;
if ((dt_progress < 0 && _progress <= _progressTargetValue)
|| (dt_progress > 0 && _progress >= _progressTargetValue))
{
[_progressTargetTimer invalidate];
_progressTargetTimer = nil;
_progress = _progressTargetValue;
}
[self setNeedsDisplay];
}

So I wrote this in the host view's dealloc method to invalidate the _progressTargetTimer:

_progressBar.progress = 0;

- (void)setProgress:(CGFloat)progress
{
[self setProgress:progress animated:NO];
}

- (void)setProgress:(CGFloat)progress animated:(BOOL)animated
{
@synchronized (self)
{
if (_progressTargetTimer && [_progressTargetTimer isValid])
{
[_progressTargetTimer invalidate];
}
CGFloat newProgress = progress;
if (newProgress > 1.0f)
{
newProgress = 1.0f;
} else if (newProgress < 0.0f)
{
newProgress = 0.0f;
}
if (animated)
{
_progressTargetValue = newProgress;
CGFloat incrementValue = ((_progressTargetValue - _progress) * YLProgressBarStripesAnimationTime) / YLProgressBarProgressTime;
self.progressTargetTimer = [NSTimer timerWithTimeInterval:YLProgressBarStripesAnimationTime
target:self
selector:@selector(updateProgressWithTimer:)
userInfo:[NSNumber numberWithFloat:incrementValue]
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_progressTargetTimer forMode:NSRunLoopCommonModes];
} else
{
_progress = newProgress;
[self setNeedsDisplay];
}
}
}

The dealloc method was called finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant