0

当用户点击它应该显示的表格视图的单元格时,我试图显示一个活动指示器vw,并且一旦加载详细视图,它就应该被隐藏。

但它在视图加载后显示然后隐藏。所以在视图加载时显示指示器是没有用的

内部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];

}
4

1 回答 1

3

关于线程和 iOS 的一点背景知识。对于所有 UI 元素的更改(视觉上),程序员需要在主线程中对它们进行更改。

由于activityIndicatorView是 UI 元素,它必须在主线程上运行才能显示旋转。如果您在主线程上执行其他操作,则会activityIndicatorView被阻止。因此,您不会立即看到旋转。当线程被释放时你会看到它。

如果你想让它工作,那么首先启动微调器,然后是后台线程,在 bg 线程中进行处理,完成后,进入主线程,停止微调器,最后用更改更新 UI。

希望这可以帮助...

于 2012-06-26T13:47:47.413 回答