我正在使用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
子类)方法如下:实用标记-自定义方法
+(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将init分配给应用程序的键窗口。但是,HUD未按预期显示,UI锁定等均未发生。我在上述方法中设置了一个断点,可以看到它被调用了,但是未显示HUD
从上面的内容来看,我希望HUD会显示出来,但没有其他反应,即HUD此时仅停留在屏幕上...
最佳答案
您缺少将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
}];
关于ios - MBprogressHUD未按预期显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16958441/