首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MBProgressHUD,多次崩溃

MBProgressHUD,多次崩溃
EN

Stack Overflow用户
提问于 2014-03-05 16:13:46
回答 2查看 544关注 0票数 0

我使用这个api来共享一个图像,但是它多次崩溃!我的代码运行良好,但有时MBProgressHUD会导致应用程序崩溃,对吗?

代码语言:javascript
复制
- (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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-05 16:19:34

我就是这样用它的:

代码语言:javascript
复制
[MBProgressHUD showHUDAddedTo: self.view animated: YES];
[self doVeryLongTask];
[MBProgressHUD hideHUDForView: self.view animated: YES];
票数 2
EN

Stack Overflow用户

发布于 2014-03-05 16:18:23

移除HUD后,试着显示这一点。

代码语言:javascript
复制
- (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]; 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22203115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档