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 を表示できません。これを修正するにはどうすればよいですか?