2014-03-05 110 views
0

我使用這個API共享一個圖像,但它崩潰很多次!我的代碼運行良好,但有時MBProgressHUD導致應用程序崩潰,我使用此API是否正確?MBProgressHUD,崩潰很多次

- (void)shareOther { 

    HUD = [[MBProgressHUD alloc] initWithView:self.view]; 
    [self.view addSubview:HUD]; 

    HUD.delegate = self; 
    HUD.labelText = @"Loading"; 

    [HUD showWhileExecuting:@selector(capture) onTarget:self withObject:nil animated:YES]; 


} 

- (void)capture { 


    //capture view 
    UIGraphicsBeginImageContextWithOptions(Sview.bounds.size, Sview.opaque, 0.0); 
    [Sview.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    NSString *str = [NSString stringWithFormat:@"some string"]; 
    UIActivityViewController* activityViewController = 
    [[UIActivityViewController alloc] initWithActivityItems:@[screenshot , str ] 
             applicationActivities:nil]; 

    UIViewController *vc = self.view.window.rootViewController; 
    [vc presentViewController: activityViewController animated: YES completion:nil]; 

} 


- (void)hudWasHidden:(MBProgressHUD *)hud { 
    // Remove HUD from screen when the HUD was hidded 
    [HUD removeFromSuperview]; 
    HUD = nil; 
} 
+0

可以粘貼錯誤顯示的應用程序崩潰的時候? – andreamazz

+0

什麼是崩潰? – CW0007007

+0

@ CW0007007 EXC_BAD_ACCESS –

回答

2

這是我如何使用它:

[MBProgressHUD showHUDAddedTo: self.view animated: YES]; 
[self doVeryLongTask]; 
[MBProgressHUD hideHUDForView: self.view animated: YES]; 
0

嘗試在刪除HUD後顯示此內容。

- (void)hudWasHidden:(MBProgressHUD *)hud { 
    // Remove HUD from screen when the HUD was hidded 
    [HUD removeFromSuperview]; 
    HUD = nil; 

    UIViewController *vc = self.view.window.rootViewController; 
    [vc presentViewController: activityViewController animated: YES completion:nil]; 
}