Я написал сетевой класс, который управляет всеми сетевыми вызовами для моего приложения.Есть два метода showLoadingAnimationView
и hideLoadingAnimationView
, которые будут отображать UIActivityIndicatorView в виде моего текущего view-контроллера с исчезающим фоном.Я получаю утечки памяти где-то на этих двух методах.Вот код
-(void)showLoadingAnimationView
{
textmeAppDelegate *textme = (textmeAppDelegate *)[[UIApplication sharedApplication] delegate];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
if(wrapperLoading != nil)
{
[wrapperLoading release];
}
wrapperLoading = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
wrapperLoading.backgroundColor = [UIColor clearColor];
wrapperLoading.alpha = 0.8;
UIView *_loadingBG = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
_loadingBG.backgroundColor = [UIColor blackColor];
_loadingBG.alpha = 0.4;
circlingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
CGRect wheelFrame = circlingWheel.frame;
circlingWheel.frame = CGRectMake(((320.0 - wheelFrame.size.width) / 2.0), ((480.0 - wheelFrame.size.height) / 2.0), wheelFrame.size.width, wheelFrame.size.height);
[wrapperLoading addSubview:_loadingBG];
[wrapperLoading addSubview:circlingWheel];
[circlingWheel startAnimating];
[textme.window addSubview:wrapperLoading];
[_loadingBG release];
[circlingWheel release];
}
-(void)hideLoadingAnimationView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
wrapperLoading.alpha = 0.0;
[self.wrapperLoading removeFromSuperview];
//[NSTimer scheduledTimerWithTimeInterval:0.8 target:wrapperLoading selector:@selector(removeFromSuperview) userInfo:nil repeats:NO];
}
Вот как я вызываю эти два метода
[NSThread detachNewThreadSelector:@selector(showLoadingAnimationView) toTarget:self withObject:nil];
, а затем где-то позже в коде я использую следующий вызов функции, чтобы скрыть анимацию.
[self hideLoadingAnimationView];
Я получаю утечки памяти при вызове функции showLoadingAnimationView.Что-то не так в коде или есть лучший способ показать анимацию загрузки, когда мы выполняем сетевые вызовы?