0

我有这个代码

- (IBAction)save:(id)sender {

    self.imageView.image = [UIImage imageNamed:@"loading.gif"];

    [self.view setUserInteractionEnabled:NO];
    MBProgressHUD *hudSave = [MBProgressHUD showHUDAddedTo:self.navigationController.view  animated:YES];
hudSave.labelText = @"Saving...";

    NSLog(@"save");

    UIAlertView *deco;

    if (!isVideo) {
         UIImageWriteToSavedPhotosAlbum (imageView.image, nil, nil , nil);
         deco = [[UIAlertView alloc]initWithTitle:@"Save" message:@"Your photo has been saved." delegate: nil cancelButtonTitle:@"oK" otherButtonTitles:nil];
    }else{

         //UIAlertView *explain;
        //explain = [[UIAlertView alloc]initWithTitle:@"Wait during processing" message:@"Your video is being filtered, this process may be long, depending of both video and device. Please do not close this app until task is finished." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            UIAlertView *explain;
            explain = [[UIAlertView alloc]initWithTitle:@"Wait during processing" message:@"Your video is being filtered, this process may be long, depending of both video and device. Please do not close this app until task is finished." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [explain show];

            [self InitialisationRefiltrage:urlVideo];

          //[self InitialisationRefiltrage:urlVideo];
        deco = [[UIAlertView alloc]initWithTitle:@"Save" message:@"Your video has been saved." delegate: nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
     } 

     [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
     [deco show];

    [self.view setUserInteractionEnabled:YES];

}

问题部分是如果我的文件是视频,它也直接进入“initialisationRefiltrage”(工作正常)但不显示 MBProgressHUD 和警报视图解释,并且在我的视频特征之后,它显示所有内容(解释、装饰和MBProgressHUD)。

我尝试了调度,线程等的一些东西......但我认为它做得不正确,所以你能否也给我一个线索如何做到这一点。

祝你今天过得愉快。

4

2 回答 2

1

UI 在“运行循环”中更新。

您正在进行的调用告诉 iOS 显示一些视图(警报、MUD ...),它将在下一次循环运行时执行此操作。

您需要做的是等待用户响应警报,然后再继续。为此,您可以将自己设置为 UIAlert 的委托,然后响应事件:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    ...
}

还有一些可用的库允许您将块传递给警报视图,从而简化整个事情。(例如https://github.com/jivadevoe/UIAlertView-Blocks

PS 我看到您是 Stack Overflow 的新手 - 如果您对我的回答感到高兴,请勾选我的回答...

于 2012-10-03T09:55:08.713 回答
1

将代码[self InitialisationRefiltrage:urlVideo]放在您的委托方法中,UIAlertView以便仅在显示警报并且用户点击警报按钮时执行它。

您也可以改用一些第三方 UIAlertView 子类,这些子类使用完成块来使您的代码仅在解除警报时执行。例如,请参阅我的课程

此外,您应该尊重编码约定并使用以小写字母开头的方法名称,以使您的代码更具可读性。

于 2012-10-03T09:58:09.787 回答