来自 ViewDidLoad 的 MBProgressHUD 调用
我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 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.
尝试下面的代码,它在我这边工作正常。
Try below code, its working fine at my end.