在调用 GCD 进程之前,我有下面的代码显示 ActivityIndicator。后台进程在完成或遇到错误时会引发通知。我在错误处理程序中调用 stopAnimating 方法,但微调器一直在旋转。为什么?
UIActivityIndicatorView *mIndicator;
@interface VC_Main ()
@end
- (void)viewDidLoad
{
[super viewDidLoad];
[NSLog(@"viewDidLoad");
// create indicator for download activity
mIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[mIndicator setCenter:CGPointMake([self getScreen].x /2.0, [self getScreen].y / 2.0)]; // landscape mode
[self.view addSubview:mIndicator];
// fire off a single interval
[NSTimer scheduledTimerWithTimeInterval:0.0
target:self
selector:@selector(timerTask:)
userInfo:nil
repeats:NO];
...
}
- (void) timerTask:(NSTimer *) timer
{
NSLog(@"DEBUG: timertask timeout");
[mIndicator startAnimating];
...
}
// if there is an error parsing xml downloaded from server, it notifies here
- (void) xmlError:(NSNotification *)note
{
NSLog(@"error parsing xml");
[mIndicator stopAnimating]; // this doesn't work
// fire off a refresh using retry timeout
[NSTimer scheduledTimerWithTimeInterval:TIMEOUT_RETRY_MINS
target:self
selector:@selector(timerTask:)
userInfo:nil
repeats:NO];
NSLog(@"will retry in %d", TIMEOUT_RETRY_MINS);
}