1

我有一个类变量imageViewUIImageView一个按钮。图像数组是使用资产从图库中加载的。完成所有图像的加载后,我将显示第一张图像:

 - (void)showImage
{

if ([images count] > 0)
    [self.imageView setImage:[images objectAtIndex:0]];
currentPage = 0;
    }

到目前为止一切都很好

但是当我通过以下操作点击按钮时:

- (IBAction)buttonNext:(id)sender {

 NSLog(@"images array   %@", images );
if (currentPage <   [images count]-1)
  {
   NSLog(@"next currentPage %d %d %@",currentPage, [images count],[images objectAtIndex:currentPage])
    currentPage++;
    [self.imageView setImage:[images objectAtIndex:currentPage]];
  }
}

没有图像替换发生。卡住了之前的imageView图像。我调试了图像数组:

 images array   (
  "<UIImage: 0xb38cec0>",
  "<UIImage: 0xb0f8280>",
  "<UIImage: 0xb063360>",
  "<UIImage: 0xb0660a0>"
)

编辑 加载图像的代码:

-(void)loadImage:(NSString*)url
{
  ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];

  ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
  {


    ALAssetRepresentation *rep = [myasset defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];
    if (iref) {
        UIImage *largeImage = [UIImage imageWithCGImage:iref];
        CGSize size=CGSizeMake(400, 500);//set the width and height
        UIGraphicsBeginImageContext(size);
        [largeImage drawInRect:CGRectMake(0,0,size.width,size.height)];
         UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

        //here is the scaled image which has been changed to the size specified
        UIGraphicsEndImageContext();
        [images addObject:newImage];

        if  ([images count] == [pages count])
            [self showImage];

    }
};

ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
{
    NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};

NSURL *asseturl = [NSURL URLWithString:url];


 [assetslibrary assetForURL:asseturl
                resultBlock:resultblock
               failureBlock:failureblock];

}
- (void)viewWillAppear:(BOOL)animated

for(NSDictionary* a in pages)
    {
        if ([a objectForKey:@"iospath"] != nil)
            [self loadImage:[document objectForKey:@"iospath"]];
    }

pages是在 viewDidLoad 中加载的数组。图像在那里。为什么我不能向他们展示?问候

4

0 回答 0