UIAle都没有在UIAlertView上显示UIActivityIndi​​catorView

时间:2013-10-24 16:42:17

标签: ios objective-c ios7 uialertview uiactivityindicatorview

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

有人可以帮忙吗?谢谢!

3 个答案:

答案 0 :(得分:3)

你试过这个吗?

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

在标准提醒视图中获取自定义内容。

答案 1 :(得分:0)

您需要在主线程中显示alertView和activityIndi​​cator,

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

答案 2 :(得分:0)

在iOS 7上无法实现

UIAlertView addSubview in iOS7

使用自定义提醒视图,试试这个

https://github.com/jdg/MBProgressHUD