当用户点击它应该显示的表格视图的单元格时,我试图显示一个活动指示符。一旦加载了详细视图,它就应该被隐藏。
但它会在加载视图后显示然后隐藏。所以在视图加载时显示指标是没用的
在viewdidload中:
activityBgImageView = [[UIView alloc] initWithFrame:self.view.frame];
[activityBgImageView setBackgroundColor:[UIColor blackColor]];
[activityBgImageView setAlpha:0.7];
[activityBgImageView setCenter:self.view.center];
[activityBgImageView setHidden:YES];
activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityIndicatorView setCenter:CGPointMake(self.view.center.x+15, self.view.center.y-15)];
[activityIndicatorView setHidesWhenStopped:YES];
[activityBgImageView addSubview:activityIndicatorView];
[self.view addSubview:activityBgImageView];
这是我的表格代码选择:
if([arrPostsData count]>0)
{
[self startActivityIndicatorView];
[self performSelector:@selector(showDetailVw) withObject:nil];
}
-(void)showDetailVw
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
detailVwBg.alpha = 0.0;
detailVwBg.alpha = 1.0;
btnBack.alpha = 1;
[self showPostDetail:arrPostsData tapedCell:detailvwScrollCount PostedFiles:arrUserPostedFilesDataDic comments:arrCommentsDataDic];
isDetailvwActive = TRUE;
[UIView commitAnimations];
}
and inside showPostDetail: method end i stop the indicator
请建议我需要输入正确的代码
这些是指标方法:
#pragma mark processindicator methods
-(void)startActivityIndicatorView{
[activityBgImageView setHidden:NO];
[activityIndicatorView startAnimating];
[self.view bringSubviewToFront:activityBgImageView];
if (![[UIApplication sharedApplication] isIgnoringInteractionEvents])
{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
}
}
-(void)stopActivityIndicatorView{
if ([[UIApplication sharedApplication] isIgnoringInteractionEvents])
{
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
[activityBgImageView setHidden:YES];
[activityIndicatorView stopAnimating];
}
答案 0 :(得分:3)
有关线程和背景的一些背景知识iOS版。对于所有要更改的UI元素(可视化),程序员需要在主线程中对它们进行更改。
由于activityIndicatorView
是一个UI元素,它必须在主线程上运行才能显示旋转。如果您在主线程上执行其他操作,则会阻止activityIndicatorView
。因此,你没有立即看到旋转。当线程被释放时,你会看到它。
如果你希望这个工作,那么首先启动微调器,然后启动后台线程,在bg线程中进行处理,完成后,进入主线程,停止微调器,最后用更改更新UI。
希望这会有所帮助......