1

我正在从 Web 服务中获取数据,在数据获取期间,我UIAcitivityIndicatorView在屏幕上显示一个。该指标在UIAlertView

UIAlertView *waitAlert = [[UIAlertView alloc] initWithTitle:@"Please Wait...." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];

    [waitAlert show];

indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(waitAlert.bounds.size.width / 2, waitAlert.bounds.size.height - 50);
[waitAlert addSubview:indicator];

NSURL *url = [NSURL URLWithString:URLString];

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSThread detachNewThreadSelector:@selector(startAnimation) toTarget:self withObject:self.view];


    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {
      // Data to populate the tableview
      [[NSOperationQueue mainQueue] addOperationWithBlock:^ {

             [self.tableView1 reloadData];
             //Stop the UIActivitiyIndicatorView
             [self stopLoading];

         }];
}];

当数据成功加载时,我可以成功关闭它,但UIActivityIndicatorView如果有人在从 Web 服务加载数据期间触摸屏幕的其余部分,我想关闭它。任何帮助将不胜感激。

4

3 回答 3

2

你能试试这个吗

在显示 UIAlertView 后,将视图添加到您的视图控制器(甚至是窗口)具有全屏大小的新空 UIView。使用 UITapGestureRecognizer 附加到这个视图

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[view addGestureRecognizer:singleTap];
[singleTap release];

-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
    [myAlert dismissWithClickedButtonIndex:0 animated:YES];
    [view removeFromSuperView];
}
于 2013-11-09T12:57:39.650 回答
0

使用touchesEnded方法

在 touches end 方法中执行停止和删除的功能UIActivityIndicatorView

-(void)touchesEnded

{

[indicator stopAnimating];

[indicator removeFromSuperView];

}
于 2013-11-09T12:57:17.607 回答
0

您可以按照以下 UIResponder 方法 -(void)touchesBegan-(void)touchesEnded

并禁用UIActivityIndicator它的内部。

于 2013-11-09T12:51:40.043 回答