サーバーに JSON ファイルの内容をロードする TableView を持つプロジェクトに取り組んでいます。すべて正常に動作しますが、2 つの問題があります。
1) ビューを変更して別のビューをロードすると、この TableView に戻ったときに ... TableView がコンテンツを再ロードしようとすると、エラーは発生しませんが、プログレス バーが短時間表示されます。これを回避するにはどうすればよいですか?
2) 私の 2 番目の問題は、いったん読み込まれると、インターネット接続が失われてビューを変更すると、コンテンツが失われることです。私もダウンロード済みです。この情報のキャッシュをどのように行うのですか?
コードは次のとおりです。
@interface ProgramacaoTableViewController ()
{
// Object thats hold the content
MProgramacao *_programacao;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// TS MESSAGE
[TSMessage setDefaultViewController:self];
[self.navigationController.navigationBar setTranslucent:YES];
// Add Refresh Control
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
////
// Check Connection and Load Data
if ([self IsConnected]) {
// YES INTERNET
// show loader view
[ProgressHUD show:@"Loading.."];
// fetch the feed
_programacao = [[MProgramacao alloc] initFromURLWithString:@"http://myurl..."
completion:^(JSONModel *model, JSONModelError *err) {
//hide the loader view
[ProgressHUD dismiss];
//json fetched
[self.tableView reloadData];
}];
}
else {
// NO INTERNET
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Error Message", nil)
subtitle:NSLocalizedString(@"try again", nil)
type:TSMessageNotificationTypeError];
}
}
コードを編集します。