UIImage setImage有时不起作用

时间:2013-09-13 11:20:25

标签: ios uiimageview

我有一个类imageView的类变量UIImageView和一个按钮。 使用Assets从Gallery中加载图像数组。 完成所有图像的加载后,我会显示第一张图像:

 - (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中加载的数组。图像在那里。为什么我不能炫耀? 此致

0 个答案:

没有答案