我有项目的存储位置分贝。 这些项目可以是不同类型的,如文本,视频和图像类型。 当查看加载我取从DB这些项目,我告诉他们在一个UITableView。 我现在面临的问题是,以显示表视图图像相关。 基本上在DB I存储与图像的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:
性能似乎更好,但它需要更多的时间来获取图像。
任何帮助将非常感激。
谢谢!