【问题标题】:upload image from url in scroll view在滚动视图中从 url 上传图像
【发布时间】:2011-07-05 10:58:24
【问题描述】:

我在滚动视图中有图像数组。当我点击图片时,我想从 url 上传更大的图片。 例如,我点击图像“page-001.jpg”然后检查图像数据,然后在图像视图上上传更大的图像并返回选项,以便返回到以前的图像视图。

【问题讨论】:

    标签: iphone xcode uiview uiscrollview xcode4


    【解决方案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];
    }
    

    【讨论】:

    • 我如何用 tap 功能实现它?
    • 在 ImageView 上保留一个自定义按钮,并将选择器分配给我上面的代码
    【解决方案2】:

    您可以使用SDWebImage。只需将文件添加到您的项目并使用

    [UIImageview setImageWithURL:(NSURL*)url];
    

    这个库还管理缓存,并且在 UITableViewCell 中运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      相关资源
      最近更新 更多