我正在尝试添加一个带有一些信息文本的活动指示器来显示网络活动,在这种情况下,是一个 web 服务调用。我的警报视图在 Web 服务调用期间正确显示,但我无法让活动指示器视图显示在警报视图上。
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSString *loadingText = [NSString stringWithFormat:@"Loading %@ gauges...", [self stateIdentifier]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:loadingText delegate:self cancelButtonTitle: nil otherButtonTitles: nil];
alert.frame = CGRectMake(0,0,300,200);
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithFrame:
CGRectMake(roundf((screenRect.size.width - 50) / 2),
roundf((screenRect.size.height - 50) / 2),50,50)];
spinner.color = [UIColor blackColor];
[alert addSubview:spinner];
[self.tableView bringSubviewToFront:alert];
spinner.hidesWhenStopped = YES;
spinner.hidden = NO;
[spinner startAnimating];
[alert show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
stateGauges = [[GaugeList alloc] initWithStateIdentifier:stateIdentifier andType:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[spinner stopAnimating];
[alert dismissWithClickedButtonIndex:-1 animated:YES];
});
});
}
有人可以帮忙吗?谢谢!