Reputation: 2413
I am using a MBProgressHUD and I need to show it on window as I want to add many full screen views. I set HUD with a text and when i change the text later, its not changing the text. HUD is a retained property of a singleton class. When i show it on view it allow me to do so. But i need to do it with window.
_HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[[UIApplication sharedApplication].keyWindow addSubview:_HUD];
_HUD.delegate=self;
_HUD.labelText =HUD_TEXT_LOADING;
_HUD.detailsLabelText =HUD_TEXT_PLEASE_WAIT;
[_HUD show:YES];
This is how i am changing the text
-(void) changeHUDText:(NSString*)text andDetailText:(NSString*) detailText
{
if (_HUD) {
if (text)
_HUD.labelText=text;
if (detailText)
_HUD.detailsLabelText=detailText;
}
}
Upvotes: 1
Views: 1043
Reputation: 81
You should just add this method to the header file of MBProgressHud:
+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view withText:(NSString *)text;
And implement it in the .m file as follows:
+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view withText:(NSString *)text
{
MBProgressHUD *hud = [[self alloc] initWithView:view];
hud.labelText = text;
[view addSubview:hud];
[hud show:YES];
return MB_AUTORELEASE(hud);
}
and call it wherever you want like:
[MBProgressHUD showHUDAddedTo:self.view withText:@"Loading..."];
Upvotes: 2