来自 ViewDidLoad 的 MBProgressHUD 调用

发布于 2024-12-08 04:01:38 字数 701 浏览 0 评论 0原文

我从 MBProgressHUD 调用我的 rss 解析器,目前它在 viewdidappear 中并且可以工作,但是我希望它在 viewdidload 中,所以当我返回时它不会重新加载它 - 但是当我将它移入 viewdidload 时它会运行该进程,但不会MBProgressHUD。

- (void)viewDidLoad {
    [super viewDidLoad];

        self.title = @"Results";

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];


    [self.view.window addSubview:HUD];
    HUD.delegate = self;

    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"updating data";

    //Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(loadResults) onTarget:self withObject:nil animated:YES];


    }

有什么想法吗?

谢谢,汤姆

I call my rss parser from MBProgressHUD and at the moment it's in viewdidappear and it works, however I want it in viewdidload so when I go back it doesn't reload it - however when I move it in to viewdidload it runs the process but not the MBProgressHUD.

- (void)viewDidLoad {
    [super viewDidLoad];

        self.title = @"Results";

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];


    [self.view.window addSubview:HUD];
    HUD.delegate = self;

    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"updating data";

    //Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(loadResults) onTarget:self withObject:nil animated:YES];


    }

Any ideas?

Thanks, Tom

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

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

发布评论

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

评论(2

红焚 2024-12-15 04:01:38

在 viewDidLoad 方法中, self.view 将在没有其父视图和窗口的情况下加载。例如, self.view.superview 将在 viewWillAppear 方法中加载,然后 self.view.window 将在 viewDidAppear 方法中加载。这就是为什么 [self.view.window addSubview:HUD] 不会在 viewDidLoad 中发生,但 [self.view addSubview:HUD] 可以工作。

In viewDidLoad method, the self.view will be loaded without its superview and window. For Example, self.view.superview will be loaded in viewWillAppear method, then self.view.window will be loaded in viewDidAppear method. That's why the [self.view.window addSubview:HUD] won't be happened in viewDidLoad, but the [self.view addSubview:HUD] works.

十年不长 2024-12-15 04:01:38

尝试下面的代码,它在我这边工作正常。

- (void)viewDidLoad {
    [super viewDidLoad];    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"updating data";    
}

Try below code, its working fine at my end.

- (void)viewDidLoad {
    [super viewDidLoad];    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"updating data";    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文