2011-07-05 26 views
1

我在滾動視圖中有圖像數組。當我點擊圖片時,我想從網址上傳更大的圖片。例如 例如我點擊圖像「page-001.jpg」,然後檢查圖像數據,然後在圖像視圖上上傳更大的圖像並返回選項,以返回到上一圖像視圖。在滾動視圖中從url上傳圖像

回答

1

試試這個

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

可以將我的項目代碼添加到我的代碼中? – ram

1

您可以使用SDWebImage。只需將文件添加到您的項目中,然後使用

[UIImageview setImageWithURL:(NSURL*)url]; 

此庫還管理緩存,並且在UITableViewCell中工作得很好。