我编写了小型测试应用程序,但没有用。这是我的故事板:
ios - iOS:导航栏中的UIActivityIndi​​cator没有停止-LMLPHP
(来源:cs618122.vk.me

这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIActivityIndicatorView* ai = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    UIBarButtonItem* rightButton = [[UIBarButtonItem alloc] initWithCustomView:ai];
    self.navigationItem.rightBarButtonItem = rightButton;
    [ai startAnimating];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        [NSThread sleepForTimeInterval: 5];
        NSLog(@"STOP!");
        [ai stopAnimating];
    });
}


这是工作结果:
ios - iOS:导航栏中的UIActivityIndi​​cator没有停止-LMLPHP
(来源:cs618122.vk.me

怎么了?

最佳答案

这是解决的相同问题:

[spinner startAnimating];
dispatch_async(kBgQueue, ^{
    // ... do other stuff in the background
    dispatch_async(dispatch_get_main_queue(), ^{
        [spinner stopAnimating];
   });
});


UIActivityIndicatorView won't stop

10-01 23:05