문제

i have a table that parse through an XML and get values for images loaded by URL links. There is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    UILabel *labelText = (UILabel *)[cell viewWithTag:1000];
    labelText.text = [[self.listOfPlaceDetails objectAtIndex:indexPath.row] objectForKey:@"name"];

    if (cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){


    }];

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

return cell;
}

Yes, it works, but now i need to modify my UIImage (with category, for making it right size), and i simply can't get reference to it. When i tried to modify an image in completion block like this :

 [cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){

        [image resizedImageWithBounds:CGSizeMake(66, 66)];

    }];

There is absolutely no effect, even when i change image for nil, its actually did nothing, so my question is: how to get instance variable of UIImage in method:

[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){


    }];

and modify it? Or how could i pass instance variable of UIImage for this method that i created before? That question may sound silly, but i need advice.

Any help would be appreciated, thanks!

도움이 되었습니까?

해결책

Assuming no error is returned to the completion block, [image resizedImageWithBounds:CGSizeMake(66, 66)]; will create a new image for you, but you still need to do something with it:

UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
cell.imageView.image = image;

You do need to be careful though, the cell may have been reused before the image is ready, so using cell in the block could be wrong. Better:

UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = resizedImage;

다른 팁

SDWebImage have image downloader, you can download image, change everything you need and set to imageView

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top