Ios 活动指示灯未显示
我正在实现iOS活动指示器的标准代码,但没有显示出来。以下是我的建议: 在Ios 活动指示灯未显示,ios,activity-indicator,Ios,Activity Indicator,我正在实现iOS活动指示器的标准代码,但没有显示出来。以下是我的建议: 在viewDidLoad中: indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; indicator.frame = CGRectMake(0, 0, 80.0, 80.0); indicator.hidden = NO; indicator.center =
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;
然后在调用我的长过程方法之前,在视图中将出现:
[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];
}
}
在我看来,这应该行得通。但事实并非如此。我错过了什么 应该在主线程上而不是在新线程中调用startAnimating
。
所以只需调用[指示器开始显示]视图中的code>将出现
无论何时您想要操纵视图(如添加子视图等),最好在ViewWillView中进行操作。viewDidLoad操作视图为时尚早,因为其他方法仍将更改它(即setFrame)
因此,将当前代码从viewDidLoad移动到ViewWillDisplay应该可以做到这一点 UIKit
应仅从主线程调用,仅在主线程上更新UI[指示器将subview带到前面:self.view]
您可能指的是[self.view将subviewTofront:indicator]代码>谢谢,@Jkmn,我改了,但还是没有运气。我放了两个indicator.I动画化日志,一旦启动它,它就会动画化,在数据库获取过程中持续5-7秒,然后停止。但在屏幕上——娜达。我想我应该补充一点,我现在在xCode 5上,用最新的OS7在iPhone4S上运行应用程序。仍然没有显示任何指示灯。我甚至试着对[indicator stop animating]进行注释,但什么也没做。我的指标声明是否正确?您能否发布指标
的声明,同时使用断点,并确保指标
不是nil
。声明在我的问题中。我做了一个NSLog,指示灯不是零。