我有下面的代碼顯示一個ActivityIndicator調用GCD過程之前。後臺進程在完成或遇到錯誤時會引發通知。我在錯誤處理程序中調用stopAnimating方法,但微調控制器仍在旋轉。爲什麼?爲什麼我的UIActivityIndicator不停止旋轉?
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);
}
是的,就是這樣。謝謝。 – wufoo
超級有用答案。經過幾個小時的谷歌搜索和嘗試不同的解決方案後,我無法弄清楚這一點。 – Neeku