MBProgressHud没有被正确解雇

时间:2013-09-26 13:00:37

标签: ios objective-c mbprogresshud

在我绘制图形的应用程序中,可以选择将图形作为图像发送,并将图形保存到照片库。但是图表可能包含多达4000个数据或更多,因此获取图像需要时间。因此,我在一个单独的线程上进行该工作,并使用进度hud来指示活动,如下所示:

- (void)sendImageAsMail
{
    if ([MFMailComposeViewController canSendMail])
    {
        // Configure HUD
        self.myHUD.mode = MBProgressHUDModeIndeterminate;
        self.myHUD.labelText = @"Acquiring image, please wait";
        self.myHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        __block UIImage *graphImage;

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
        ^{
            CPTGraph *currentGraph = self.hostView.hostedGraph;
            graphImage = [currentGraph imageOfLayer];
            self.imageData = UIImagePNGRepresentation(graphImage);
            [[NSNotificationCenter defaultCenter] postNotificationName:@"mailReady" object:nil];
        });
    }
    else
    {
        [self showAlertWithTitle:@"Cannot Send Mail" andText:@"Your mail configuration is incorrect"];
    }
}

- (void)mailReady:(NSNotification *)notification
{
    MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
    mailVC.mailComposeDelegate = self;
    [mailVC setSubject:[NSString stringWithFormat:@"some subject here (%@)", [[[iDSConstants sharedConstants]codeTypes] objectAtIndex:_codeIndex]]];
    [mailVC setMessageBody:@"some body" isHTML:NO];
    [mailVC addAttachmentData:self.imageData mimeType:@"image/png" fileName:@"Design Spectrum"];

    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

    [self presentViewController:mailVC animated:YES completion:nil];
}

现在有趣的是,在呈现mailviewcontroller之前,hud不会被解雇(或隐藏,如果可能的话);如果我按下取消并关闭电子邮件,我可以看到hud旋转,并继续旋转几秒钟。我尝试了其他方法,例如在代码的不同位置解除hud:

(上面代码的一部分)

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
    CPTGraph *currentGraph = self.hostView.hostedGraph;
    graphImage = [currentGraph imageOfLayer];
    self.imageData = UIImagePNGRepresentation(graphImage);

    **// get main thread for dismissing the hud
    dispatch_async(dispatch_get_main_queue(), ^{
       [MBProgressHUD hideHUDForView:self.view animated:YES];
    });**

    [[NSNotificationCenter defaultCenter] postNotificationName:@"mailReady" object:nil];
});

但我仍然可以看到之前应该隐藏的地方。任何关于这个问题的见解将不胜感激。

0 个答案:

没有答案