surferbloggy 0 Newbie Poster

Hi in my app there is an image thumbnail for each table cell
it works but when the image there isn't for that row i'd like to show a default image the image url is retrieved from an html string and put into an array could you help me to write this code?it shows the image when there is but not the default image when there isn't any image

 if ([[item imagesFromContent] count]>0) {

        //if added

        if([[item imagesFromContent] objectAtIndex:0]){
            [cell.thumbnail setImageWithURL:[NSURL URLWithString:[[item imagesFromContent] objectAtIndex:0]]
                           placeholderImage:[UIImage imageNamed:@"thumb.png"]];


        }else{
        //default image
            [cell.thumbnail setImageWithURL:[NSURL URLWithString:@"img415x280.png"]
                           placeholderImage:[UIImage imageNamed:@"thumb.png"]];
        }
    }

i've tryed also this way

-(NSArray *)imagesFromHTMLString:(NSString *)htmlstr
{
    NSMutableArray *imagesURLStringArray = [[NSMutableArray alloc] init];

    NSError *error;

    NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:@"(https?)\\S*(png|jpg|jpeg|gif)"
                                  options:NSRegularExpressionCaseInsensitive
                                  error:&error];

    [regex enumerateMatchesInString:htmlstr
                            options:0
                              range:NSMakeRange(0, htmlstr.length)
                         usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

                               //if added

                            if ([htmlstr substringWithRange:result.range]!=nil) {
                                 [imagesURLStringArray addObject:[htmlstr substringWithRange:result.range]];
                             }else{
                                 [imagesURLStringArray addObject:@"img415x280.png"];
                             }
                                                      }];

    return [NSArray arrayWithArray:imagesURLStringArray];
}

thank you for help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.