Pregunta

I am using MBRProgressHUD with a storyboard setup.

I present a Login view controller which handles the login. Once a user is received I present another view controller like this:

self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeVC"];

Within my login method I create my HUD with the following:

// Start the HUD outside the user login block
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
self.HUD.dimBackground = NO;
self.HUD.labelText = NSLocalizedString(@"HUDLoggingInText", @"Login HUD Logging in text");

This all works fine the issue I have is with dismissing the view controller. Before using storyboards I was able to add the following:

// Bring down the HUD with a success message
self.HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
self.HUD.mode = MBProgressHUDModeCustomView;
self.HUD.labelText = NSLocalizedString(@"HUDLoggedInText", @"HUD Logged in text");
[self.HUD hide:YES afterDelay:2];

This would bring down the HUD with a success checkmark and different text. The issue I have now is that when the HomeVC is loaded using the first line of code above the Login view controller (and the navigation controller it lives on) is deallocated which I think means the HUD is lost too.

How can I have the HUD show the success before instantiateViewControllerWithIdentifier? I have tried the obvious moving the HUD part before the load of the HomeVC but this makes no difference, neither does changing the delay to 0.

EDIT Views loaded. The first view the storyboard loads is the class InitialViewController. This then instaniates another controller based on if the user is logged in:

    self.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"WelcomeVC"];
} else {
    NSLog(@"logged in");
    self.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeVC"];

The initial View controller always remains on the stack and is an ECSlidingViewController so it has a property for the topViewController.

Ideally I need to know how to add the HUD to this initialViewController on the stack, I guess rather than the currently displayed view (Login View Controller) as that is deallocated when the login is complete and a new view controller loaded with 'instantiateViewControllerWithIdentifier' again.

¿Fue útil?

Solución

The HUD should not be lost. You just lose the reference to it if the controller holding the reference is deallocated.

Solution: just pass the reference to the HUD to your home view controller. Or create the home view controller before (without showing it) and do all the HUD logic in there.

To pass the reference:

self.topViewController.hud = hud;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top