如何显示UIAlertView显示时消失的MBProgressHUD?

时间:2013-01-25 15:16:08

标签: ios uialertview mbprogresshud

我的应用程序显示MBProgressHUD在从服务器获取数据时添加到主窗口。如果需要登录,则显示UIAlertView以提示用户输入用户名&密码。当UIAlertView显示时,MBProgressHUD隐藏 - 这不是由于我的代码中的任何内容,但它是我想要的行为。但是,当UIAlertView消失时,我希望HUD能够回来。我可以通过致电[MBProgressHUD allHUDsForView:window]来获取他们,但他们的超级视图现在为nil,并且调用-[show:]无效。

如何显示在显示UIAlertView时消失的MBProgressHUD?

1 个答案:

答案 0 :(得分:0)

这不是您确切问题的答案,而是解决问题的另一种方法,

我会试着控制自己的进步,因为我知道我是那个叫uilaertview并且贬低它的人。为什么不使用两个huds?

// Add when your fetch method is called
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.labelText = @"Loading...";


//in your alertview method
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                    message:@"Message"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];

    //dissmiss progress hud before alertview is shown
    [MBProgressHUD hideHUDForView:self.view animated:YES];

    [alert show];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"OK"])
    {
        NSLog(@"OK button is clicked on alertview");

         //show another hud
         MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.labelText = @"Loading...";

    }
}