MBProgressHUD,多次崩溃

时间:2014-03-05 16:13:46

标签: ios iphone objective-c

我正在使用这个api共享图像,但它崩溃了很多次!我的代码运行正常,但有时MBProgressHUD导致应用程序崩溃,我使用这个API吗?

- (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;
}

2 个答案:

答案 0 :(得分:2)

这就是我使用它的方式:

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

答案 1 :(得分: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]; 
}
相关问题