我正在使用以下代码在加载某些数据时显示活动指示器。问题是当我试图再次隐藏它时。活动指标保持不变。屏幕稍微变亮但就是这样。
要表明:
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
[self.tableView addSubview:self.overlayView];
隐藏它:
[self.activityIndicator stopAnimating];
[self.overlayView removeFromSuperview];
答案 0 :(得分:0)
尝试将overlayView添加到tableView的超级视图中:
[self.view.superview addSubview:self.overlayView];
答案 1 :(得分:0)
我用stackoverflow问题的组合想出来了。这是我的代码,以显示UIActivityIndicatorView
-(void)loadView {
[super loadView];
self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.tableView addSubview:self.overlayView];
[self.activityIndicator startAnimating];
}
以下是隐藏它的代码。看起来像将代码放在loadView事件中就完全不同了。
[overlayView removeFromSuperview];