我正在实现似乎是 iOS 活动指示器的标准代码,但它没有显示。这就是我所做的,遵循这里的建议:
在viewDidLoad
:
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0, 0, 80.0, 80.0);
indicator.hidden = NO;
indicator.center = self.view.center;
[self.view insertSubview:indicator atIndex:100]; // to be on the safe side
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
然后在viewWillAppear
,就在调用我的长流程方法之前:
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
我的线程开始动画:
-(void)threadStartAnimating:(id)data
{
[indicator startAnimating];
}
然后我有一个 Parse.com 方法在后台做一些工作:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error) {
// do some work
[indicator stopAnimating];
}
}
据我所知,这应该可行。但事实并非如此。我错过了什么?