首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AlAsset库的问题

AlAsset库的问题
EN

Stack Overflow用户
提问于 2011-11-01 14:57:20
回答 1查看 770关注 0票数 0

我面临着ALAsset库的一个问题:我有一个具有100个图像视图的UIView。当视图加载时,我将调用一个函数,用于从文件名生成图像。

这是我的课:

代码语言:javascript
运行
复制
@interface myClass
{
    NSString *fileName;
    int pathId;
}

viewDidLoad

代码语言:javascript
运行
复制
-(void)viewDidLoad
{
    NSMutableArray *imageCollectionArray = [self createImage:arrayOfmyClassObject];

     //Here I'm binding the 100 images in UIView using the images in imageCollectionArray
}

这是我发现问题的方法:

代码语言:javascript
运行
复制
- (NSMutableArray *)createImage:(NSMutableArray *)imageFileNamesArray 
{
    imageArray = [[NSMutableArray alloc] init]; 
    for (int imageNameKey = 0; imageNameKey<100; imageNameKey++) 
    {
         myClass *obj= [imageFileNamesArray objectAtIndex:imageNameKey];
        if(obj.pathId == 0)
        {

            //Here adding the bundle image into the imageArray
                [imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:obj.fileName ofType:@"png" inDirectory:@"Images"]]];
        }
        else
        {
                typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset); typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
             ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
             };
             ALAssetRepresentation *rep = [myasset defaultRepresentation]; 
            CGImageRef iref = [rep fullResolutionImage];
            UIImage *images; 
            if (iref)
                {

            //Here adding the photo library image into the imageArray
             images = [UIImage imageWithCGImage:iref];
            [imageArray addObject:images];

            }
            else
            {
            //Here adding the Nofile.png image into the imageArray if didn't find a photo library image
              images = [UIImage imageNamed:@"Nofile.png"];
             [imageArray addObject:images];
            }

             ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {

                        //Here adding the Nofile.png image into the imageArray if any failure occurs
                 [imageArray addObject:[UIImage imageNamed:@"Nofile.png"]]; 

            NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
             };
             NSURL *asseturl = [NSURL URLWithString:obj.fileName];
             ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease]; 
            [assetslibrary assetForURL:asseturl
             resultBlock:resultblock failureBlock:failureblock];
        }
    }
    return imageArray;
}

问题是,当我第一次加载该视图时,资产库映像没有生成,只显示了捆绑图像,如果我转到另一个视图并返回到100个图像视图,那么资产映像是generated.And工作得很好。问题是相同的函数不是在第一次加载时生成资产映像。我怎么才能解决这个问题?提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2011-11-02 14:11:23

所有与ALAssetLibrary相关的方法都是异步的,因此您的视图可以在返回所需数据之前完成其加载生命周期。您必须考虑到这一点,并根据需要重新绘制视图(或视图的一部分)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7968359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档