MBProgressHUD 对另一个类隐藏

发布于 2024-12-01 11:06:52 字数 855 浏览 0 评论 0原文

我有一个处理网络服务请求的类。当它开始从服务获取信息时,我创建并在另一个类视图上添加 HUD。像这样,

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

当加载完成时,我调用它,

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

我将委托设置为 self,

HUD.delegate = self;

但我无法将其从视图中删除。

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

我想从一个类开始,然后在另一个类上显示,而第一个类是从网络服务获取数据。然后把我从第一堂课中隐藏起来。

有什么想法吗?

编辑:

好的,现在我将第一类中的委托设置为:

HUD.delegate = viewController;

但是我该放在哪里:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯狂的代价 2024-12-08 11:06:52

您可以通过将 HUD 的委托设置为其他类来做到这一点。

例如,如果我在 A 类中添加 HUD,并希望将其从 B 类中删除,那么我必须将 HUD 委托设置为 B 类。

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.

水水月牙 2024-12-08 11:06:52

您可以使用第一次调用中的完成块,并在从网络服务获得答案后继续工作,以将 HUD 隐藏在块中。

长长的一行:

[self callServiceWithBlock:^(NSError *error){

//Your service has answered, you can now hide the HUD

    [hud HIDE:YES];
    if (error){
        NSLog(@"Error : %@");
    }


}];

You could use a completion block from your first call and work your way up once you got an answer from the webservice, to hide the HUD in the block.

Something long the lines of :

[self callServiceWithBlock:^(NSError *error){

//Your service has answered, you can now hide the HUD

    [hud HIDE:YES];
    if (error){
        NSLog(@"Error : %@");
    }


}];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文