2011-07-05 10 views
1

私はスクロールビューで画像の配列を持っています。私は画像をタップすると、URLから大きな画像をアップロードしたい。 例えば、画像 "page-001.jpg"をタップして画像データを確認し、大きな画像を画像ビューにアップロードして戻って、前の画像ビューに戻ることができます。スクロールビューのURLから画像をアップロード

答えて

1

はあなたがSDWebImageを使用することができ、この

NSMutableArray *arr = [[NSArray alloc] initWithObjects:imageURL,imageView.tag, nil]; 
[self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr]; 



- (void) loadImageInBackground:(NSArray *)urlAndTagReference 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    // Retrieve the remote image. Retrieve the imgURL from the passed in array 
    NSURL *imgUrl=[[NSURL alloc] initWithString:[urlAndTagReference objectAtIndex:0]];     
    NSData *imgData = [NSData dataWithContentsOfURL:imgUrl]; 
    UIImage *img = [UIImage imageWithData:imgData]; 
    [imgUrl release]; 

    // Create an array with the URL and imageView tag to 
    // reference the correct imageView in background thread. 

    NSMutableArray *arr = [[NSMutableArray alloc ] initWithObjects:img,[urlAndTagReference objectAtIndex:1], nil ]; 

    // Image retrieved, call main thread method to update image, passing it the downloaded UIImage 

    [self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr waitUntilDone:YES]; 
    [arr release]; 
    [pool release]; 
} 

- (void) assignImageToImageView:(NSMutableArray *)imgAndTagReference 
{ 
    UIImageView *profilePic = (UIImageView *)[cell.contentView viewWithTag:20]; 
    imageView.image = [imgAndTagReference objectAtIndex:0]; 
} 
+0

タップ機能で実装する方法は? – ram

+0

ImageView上にカスタムボタンを置いて、上のコードにボタンのセレクタを割り当てます – iPrabu

+0

は私のプロジェクトコードでurコードを追加できますか? – ram

1

を試してみてください。プロジェクトにファイルを追加して使用するだけです。

[UIImageview setImageWithURL:(NSURL*)url]; 

また、このライブラリはキャッシュを管理し、UITableViewCellでうまく動作します。

関連する問題