2012-07-14 116 views
2

我使用一個按鈕,點擊或(IBAction爲)內以下UIAlertView中不解僱

- (IBAction)HistoryBtn:(id)sender { 
    self startReport]; 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     //============================ 
      so some long processing code   
     //============================    
     [self stopReport]; 
    }); 
} 

-(void) startReport 
{ 
    alert = [[UIAlertView alloc] initWithTitle:@"Generating PDF" message:@" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)]; 
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 
    [alert addSubview:progress]; 
    [alert setDelegate:self]; 
    [progress startAnimating]; 

    [alert show]; 
} 

-(void) stopReport 
{ 
    NSLog(@" Stop Called "); 
    [self.alert dismissWithClickedButtonIndex:0 animated:NO]; 
    self.alert = nil; 

    NSLog(@" Stop Called "); 
} 

問題是AlertView彈出窗口了,我可以看到按鈕的工作,然後StopReport IS調用但AlertView停留在那裏我怎樣才能讓AlertView消失

在此先感謝

回答

3

只能在主線程上使用UI。

- (IBAction)HistoryBtn:(id)sender { 
    self startReport]; 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     //============================ 
      so some long processing code   
     //============================  
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self stopReport]; 
     }); 
    }); 
} 
+0

非常感謝你的 – BarryF 2012-07-14 19:07:15