iOS UIalertView 显示和处理顺序



我有这个代码

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

问题部分是,如果我的文件是视频,它直接太"初始化Refiltrage"(谁工作正常),但没有显示MBProgressHUD和警报视图解释,在我的视频特征之后,它同时显示所有内容(解释,装饰和MBProgressHUD)。

我尝试使用调度,线程等...但我认为不要做对,所以你能不能也给我一个线索,怎么做。

有好的一天。

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

您还可以改用一些第三方 UIAlertView 子类,这些子类使用完成块使代码仅在警报消除时执行。例如,请参阅我的类执行此操作。

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

UI 在"运行循环"中更新。

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

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

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

还有一些库允许您将块传递到警报视图,从而简化整个操作。(例如 https://github.com/jivadevoe/UIAlertView-Blocks)

附言我看到你是堆栈溢出的新手 - 如果你很高兴它回答了你的问题,请勾选我的答案......

最新更新