【问题标题】:MBProgressHud, AFnetworking and refreshing dataMBProgressHud、AFnetworking 和刷新数据
【发布时间】:2013-06-28 22:22:22
【问题描述】:

我正在使用 AFnetworking 调用服务器。下载时,我使用 MBProgressHUD 来显示正在下载数据。到目前为止,一切都很好。我的问题是当我按下主页按钮然后重新启动应用程序时。我希望页面自动刷新并让 MBProgressHUD 向用户显示正在下载的内容。这是我做不到的。我可以下载数据,但我无法让 HUD 部分工作。

首先,在 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]);

}];

为什么这不起作用?我可以得到数据。但我无法让 progressHud 显示。我该如何解决这个问题?

【问题讨论】:

  • 你可以尝试把代码显示progressHUD在主线程中运行吗?
  • @verbumdei 不是行“MBProgressHUD* progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];”在主线程上运行?也许我不明白你的问题......
  • 您能否打印一些日志以确认您确实成功获取了数据?还有这一行:[progressHud self.view animated:YES]; 没有意义。
  • 我知道我已经得到了数据。我刚刚决定转储 mbprogress hud,除非在少数情况下。

标签: ios asynchronous afnetworking mbprogresshud afhttpclient


【解决方案1】:

Notification Runloop 和 HTTP request runloop 可能不一样。所以显示进度HUD的方法可能不会被调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2012-09-21
    • 2019-12-29
    相关资源
    最近更新 更多