アイテムが保存されているデータベースがあります。これらのアイテムは、テキスト、ビデオ、画像など、さまざまな種類のアイテムにすることができます。ビューが読み込まれると、DB からこれらのアイテムを取得し、UITableView に表示します。私が直面している問題は、テーブル ビューに画像を表示することに関連しています。基本的に、DB に画像に関連する ALAsset リンクを保存し、そこから次のコードを使用して画像を取得しようとします。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//...Other Code
else if ([object isMemberOfClass:[Picture class]]){
//Get a reusable cell
cell = [tableView dequeueReusableCellWithIdentifier:@"pictureCellIdentifier"];
// [self performSelectorInBackground:@selector(performAsset:) withObject:dict];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
((PictureViewCell *)cell).placeHolderImageView.hidden = YES;
((PictureViewCell *)cell).pictureImageView.image = [UIImage imageWithCGImage:[rep fullResolutionImage] scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
[Utility showAlertViewWithTitle:@"Location Error" message:@"You must activate Location Services to access the photo" cancelButtonTitle:@"Dismiss"];
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:[NSURL URLWithString:((Picture *)objectInArray).imagePath]
resultBlock:resultblock
failureBlock:failureblock];
//Set the background for the cell
cell.backgroundView = iv;
}
//...Other code
}
問題は、セルをスライドするとメソッドが呼び出され、アプリが非常に遅くなることです。だから、私がやろうとしていることを達成するためのより良い方法があると思います. また、 を使用してそのコードを実行しようとしましたperformselectorInBackground:
。パフォーマンスは向上しているように見えますが、画像の取得に時間がかかります。
どんな助けでも本当に感謝しています。
ありがとう!