私のアプリケーションでは、JSON データを解析し、そのデータを UITableView に表示しています。情報は表に表示されますが、タッチの反応が非常に遅いです。いくつかの調査を行ったところ、情報、特に画像の非同期読み込みを実装することが推奨されていることがわかりましたが、JSON アプリケーションで機能する関連ソリューションが見つかりませんでした。この問題を解決する方法についての提案とコメントをいただければ幸いです。コードは次のとおりです。
jURL 定義 www.website.com/info.json
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(jQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
jURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:NO];
});
}
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* jsonDict = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
calRes = [jsonDict objectForKey:@"results"];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *calDict = [calRes objectAtIndex:indexPath.row];
NSURL *imageURL = [NSURL URLWithString:[calDict objectForKey:@"image"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *imageLoad = [[UIImage alloc] initWithData:imageData];
cell.textLabel.text = [calDict objectForKey:@"name"];
cell.detailTextLabel.text = [calDict objectForKey:@"description"];
cell.imageView.image = imageLoad;
return cell;
}