Search code examples
objective-cmbprogresshud

MBProgressHUD hide from another class


I have a class that handles request to a webservice. When this start to fetch information from the service I create and add a HUD on another class view. Like this,

HUD = [[MBProgressHUD showHUDAddedTo:viewController.view animated:YES] retain];

When the loading is finished I call this,

[HUD hideHUDForView:viewController.view animated:YES];

I set the delegate to self,

HUD.delegate = self;

But I can not get it to remove from the view.

- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}

I want to start in one class to show on another while the first is fetching data from the webservice. Then hide i from the first class.

Any ideas?

EDIT:

OK now I set the delegate in the first class to:

HUD.delegate = viewController;

But where do I put:

- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}

Solution

  • You can do this by setting the delegate of your HUD to other class.

    For example if i add the HUD in Class A and want to remove it from Class B then i have to set delegate of HUD to class B.