2013-11-09 53 views
1

我取出由Web服務的數據,並在UIActivityIndi​​catorView的數據讀取,我在屏幕上顯示一個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服務中的數據加載過程中屏幕的其他部分觸及。任何幫助將不勝感激。

回答

0

你可以做到這一點在下列UIResponder方法 -(void)touchesBegan-(void)touchesEnded

,並禁用它裏面的UIActivityIndicator

+0

如果我在UIAlertView中使用活動指示器,這樣工作嗎? – Atul

+0

沒有必要一起顯示UIAlertView和UIActivityIndi​​cator。 –

+0

但在情況下,如果你只想檢查誰是UIResponder鏈 –

0

使用touchesEnded方法

端方式的觸摸裏面的停止做功能,並刪除UIActivityIndicatorView

-(void)touchesEnded 

{ 

[indicator stopAnimating]; 

[indicator removeFromSuperView]; 

} 
+0

意志的工作,如果我在UIAlertView中使用活動的指標???? – Atul

+0

ofcourse阿圖爾... – iGautham

+0

,但它不工作 – Atul

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]; 
} 
+1

會的工作,如果我使用活動的指標在UIAlertView中???? – Atul

+1

是的,它會工作,你只是刪除視圖。 –

+1

但它不工作,因爲這種方法不被稱爲也許UIAlertView不允許它在背景上觸摸 – Atul

相關問題