作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在调用 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);
}
最佳答案
与每个 UIKit 调用一样,您需要在主线程上执行此操作。
只需这样做:
dispatch_async(dispatch_get_main_queue(), ^{
[mIndicator stopAnimating];
});
关于objective-c - 为什么我的 UIActivityIndicator 不停止旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19055513/
我是一名优秀的程序员,十分优秀!