私は私の問題を説明します、私は解決策を見つけたいと思っています。私はこれを修正する方法を数週間探していますが、それを修正する方法を見つけることができず、外部ライブラリやまれなクラスを使用したくありません。
説明:
TableViewにXMLから情報を自動的に取得させ、XMLで解析してMutableArrayに格納したすべての情報を取得します。
配列はすべてのXMLタグを解析し、正しく機能しています。
ラベルを読み取るために、パーサーを次のように実行します。
//このタグを使用するにはタイトル:
[[self.parseResults objectAtIndex:indexPath.row] objectForKey:@ "name_category_ads"];
//この画像タグを使用するには:
[[self.parseResults objectAtIndex:indexPath.row] objectForKey:@ "image1_category_ads"];
問題:
TableViewテキストは配列(タイトル)を正しくロードしますが、テーブルビューの配列から画像をロードすることはできません。
静的URL画像(Webサイトにある画像)と非同期読み込みを使用してコードをテストしましたが、配列から実行しようとしても機能しない場合は、画像のURLが異なります。
//画像のURLの例静的
NSString *imagenURL=@"http://www.principadoasturias.net/2011/pablo/03_php/archivos/iconos/jpg.jpg";
私のテーブルのコードは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
//My custom cell
Cell_Category_Iphone *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[Cell_Category_Iphone alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//Image Static URL
NSString *imagenURL=@"http://www.principadoasturias.net/2011/pablo/03_php/archivos/iconos/jpg.jpg";
//Assign the title to my cell, using my array already loaded and parsed.
cell.titleCategoryCell.text=[[self.parseResults objectAtIndex:indexPath.row] objectForKey:@"name_category_ads"];
//Asynchronous loading of image
if (!cell.imageCategoryCell.image) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
NSData *data =[NSData dataWithContentsOfURL:[NSURL URLWithString:imagenURL]];
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *thumbnail = [UIImage imageWithData:data];
cell.imageCategoryCell.image=thumbnail;
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
});
});
}
return cell;
}
問題の締めくくりは、次の内容で構成されます。
コードはasicronicaのように画像を正しくロードしますが、URLにある単一の画像ですが、配列にある画像をロードすることはできません。
//私の配列画像
[[self.parseResults objectAtIndex: indexPath.row] objectForKey: @ "image1_category_ads"];
手伝って頂けますか?次に、すべての人にコードを共有します。どうもありがとう
リカルドよろしく