0

MBProgressHUD用来显示 HUD,但未按预期显示。

步骤:用户在tableView. 解析一些数据,然后UIAlertView向用户显示警告 ( )。询问用户是否要使用所选(单元格)用户创建新游戏。取消/开始游戏按钮。

UIAlertView委托方法如下:

杂注标记 - UIAlertView 委托

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

如果用户选择开始游戏,GameModel则运行该方法。游戏模型(NSObject子类)方法如下:

pragma mark - 自定义方法

+(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.
    
}

如您所见,HUD 分配给应用程序的键窗口。但是,HUD 没有按预期显示,没有任何反应,没有 UI 锁定等。我在上面的方法中设置了一个断点,可以看到它被调用但是 HUD 没有显示

从上面看,我希望 HUD 会出现,但没有其他任何事情发生,即 HUD 只是暂时留在屏幕上......

4

5 回答 5

5

您缺少将 HUD 添加到Window然后显示 HUD 的部分。请注意,您可以将 HUD 添加到Window当前视图 ( self.view)。

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[[UIApplication sharedApplication].keyWindow addSubview:HUD]; //<-- You're missing this

HUD.dimBackground = YES;
HUD.labelText = NSLocalizedString(@"HUDCreateNewGame", @"HUD - Create New Game text");
HUD.removeFromSuperViewOnHide = YES;

[HUD showAnimated:YES whileExecutingBlock:^{ //<-- And this
  // Do something
}];
于 2013-06-06T09:41:14.743 回答
0

好的,我发现了问题。我使用clickedButtonAtIndex的方法UIAlertView当然是坚持观点。我didDismissWithButtonIndex改用了,现在效果很好。

于 2013-07-23T10:40:38.697 回答
0

尝试这个:

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.labelText = NSLocalizedString(@"HUDCreateNewGame", @"HUD - Create New Game text");
// Set determinate mode
[HUD setMode:MBProgressHUDModeDeterminate];
[self.view addSubview:HUD];
[HUD show:YES];
于 2013-06-06T09:31:51.923 回答
0

您不会将其添加到任何视图中以使其显示。所以将它添加到适当的视图中。

来自 MBProgressHUD 的 git hub 项目演示

// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
于 2013-06-06T09:33:23.087 回答
0

您没有获得显示 hud 的代码。使用以下代码

 MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 HUD.dimBackground = YES;
 HUD.labelText = NSLocalizedString(@"HUDCreateNewGame", @"HUD - Create New Game text");
于 2013-06-06T09:34:08.450 回答