UIAactivityIndicatorView 未显示在 UIAlertView 上



我正在尝试添加一个带有一些信息文本的活动指示器来显示网络活动,在本例中为网络服务调用。我的警报视图在 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];
        });
    });
}

有人可以帮忙吗?谢谢!

你试过这个吗?

[alert setValue:spinner forKey:@"accessoryView"];

以在标准警报视图中获取自定义内容。

您需要在主线程中显示 alertView 和 activityIndicator,

 dispatch_async(dispatch_get_main_queue(), ^{
   [spinner startAnimating];
    [alert show];
            });
这在

iOS 7 上是不可能的

UIAlertView addiOS7 中的子视图

使用自定义警报视图,试试这个

https://github.com/jdg/MBProgressHUD

最新更新