0
我正在使用AFnetworking调用服务器。在下载时,我正在使用MBProgressHUD显示正在下载数据。迄今为止,一切都很好。我的问题是当我按主页按钮,然后重新启动应用程序。我希望页面自动刷新,MBProgressHUD向用户显示正在下载的内容。我做不到。我可以下载数据,但我无法使HUD部分正常工作。MBProgressHud,AFnetworking和刷新数据
首先,在viewDidLoad方法我补充一点:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActiveNotificationAction)
name:UIApplicationDidBecomeActiveNotification
object:nil];
现在在方法applicationDidBecomeActiveNotificationAction
,我打电话[self downloadWebsites]
。
在该方法中downloadWebsites
是其中的大部分工作已完成:这就是:
//show the hud
MBProgressHUD* progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
progressHUD.labelText = @"Loading";
progressHUD.mode = MBProgressHUDAnimationFade;
[self.list_websites getPath:[NSString stringWithFormat:@"%@?%@", @"websites", self.auth_header] parameters: nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//download data in the success block
//refresh the ui
[self.tableView reloadData];
[progressHud self.view animated:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure block. log the error
NSLog([error description]);
}];
为什么不这项工作?我可以得到这些数据。但我无法获得进度显示。我该如何解决?
你可以尝试把代码显示进度HUD在主线程中运行? –
@ verbumdei不是行“MBProgressHUD * progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];”正在主线程上运行?也许我不理解你的问题... – user678392
你可以打印一些日志,以确认你确实成功获取数据?另外这一行:'[progressHud self.view animated:YES];'没有任何意义。 – Stunner