gpt4 book ai didi

objective-c - 为什么我的 UIActivityIndi​​cator 不停止旋转?

转载 作者:行者123 更新时间:2023-12-04 04:39:55 26 4
gpt4 key购买 nike

在调用 GCD 进程之前,我有以下代码显示 ActivityIndi​​cator。后台进程在完成或遇到错误时会抛出一个通知。我正在错误处理程序中调用 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 - 为什么我的 UIActivityIndi​​cator 不停止旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19055513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com