Search code examples
iosobjective-cios5mbprogresshud

MBprogressHUD not showing as expected


I am using MBProgressHUD to show a HUD but it is not showing as expected.

Steps: User selects a cell in a tableView. Some data is parsed then a warning (UIAlertView) is shown to the user. The user is asked if they want to create a New Game with the selected (cell) user. Cancel/Start Game buttons.

The UIAlertView delegate methods is as follows:

pragma mark - UIAlertView Delegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"button %i",buttonIndex);
    if (buttonIndex == 0) {
        // Cancel button pressed
        self.gameNewOpponentuser = nil;
    } else {
        // Start Game button pressed
        [MESGameModel createNewGameWithUser:[PFUser currentUser] against:self.gameNewOpponentuser];
    }
}

If the user selects Start Game the GameModel method is run. The game model(NSObject subclass) method is as follows:

pragma mark - Custom method

+(void)createNewGameWithUser:(PFUser *)user1 against:(PFUser *)user2 {
    // First we put a HUD up for the user on the window
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
    HUD.dimBackground = YES;
    HUD.labelText = NSLocalizedString(@"HUDCreateNewGame", @"HUD - Create New Game text");
    HUD.removeFromSuperViewOnHide = YES;
    
    // Confirm we have two users to play with.
    
}

As you can see the HUD is alloc init to the keywindow of the application. However, the HUD is not showing as expected, nothing happens no UI lockup etc. I have put a breakpoint in the above method and can see that it is called however the HUD is not displayed

From the above, I expect the HUD to show up but nothing else happen, i.e. the HUD just remain on screen at the moment...


Solution

  • Ok, I found the issue. I was using clickedButtonAtIndex method for the UIAlertView which was of course holding to the view. I used didDismissWithButtonIndex instead and this works fine now.