2017-07-26 3 views
1

In meinem RSS-Feed app, ich Parse Bilder mit NSXMLParser durch die didStartElement Methode eingeben:SDWebImage nicht geladen Bild von URL in UITableViewCell

If ([element isEqualToString: @ "item"]) { 
         
        Item = [[NSMutableDictionary alloc] init]; 
        Title = [[NSMutableString alloc] init]; 
        Link = [[NSMutableString alloc] init]; 
        PubDate = [[NSMutableString alloc] init]; 
        ImageUrl = [[NSMutableString alloc] init]; 
    } 
     
    If ([element isEqualToString: @ "enclosure"]) { 
        NSString * name = [attributeDict objectForKey: @ "url"]; 
        NSLog (@ "The URL is:% @", name); 
         
    } 

Und in der didEndElement Methode:

If ([elementName isEqualToString: @ "item"]) { 
        [Item setObject: title forKey: @ "title"]; 
        [Item setObject: link forKey: @ "link"]; 
        [Item setObject: pubDate forKey: @ "pubDate"]; 
        [Item setObject: imageUrl forKey: @ "url"]; 
        [Feeds addObject: [item copy]]; 
    } 

Ok. Das funktioniert, die Links habe ich alle.

Jetzt möchte ich diese URLs in Zellen in meinem UITableView laden. Also habe ich den 'SDWebImage' Pod benutzt.

Im cellForRowAtIndexPath Methode ich habe:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
    cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];  
    cell.textLabel.numberOfLines = 0; 
    [cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
    cell.detailTextLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"pubDate"]; 
    NSString *str = [[feeds objectAtIndex:indexPath.row] objectForKey: @"pubDate"]; 
    cell.detailTextLabel.text = str; 
    NSString * string = [[feeds objectAtIndex:indexPath.row] objectForKey: @"url"]; 
    NSLog(@"THE URL IS: %@", string); 

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:string] placeholderImage:[UIImage imageNamed:@"placeholder.gif"]]; 

    return cell; 

    } 

Aber nichts passiert. Das ist meine derzeitige Situation.

enter image description here

Wie beheben zu?

+0

Könnten Sie 'string's Wert und' [NSURL URLWithString: string] 'Wert? Die URL ist wahrscheinlich – nathan

+0

@nathan yep. Ich löse dieses Problem, aber jetzt habe ich ein anderes Problem: Die Bilder werden gesehen, aber wenn ich auf ein Bild klicke, ändert es seine Größe und wird länger..Warum? Schauen Sie http://imgur.com/YhSUiBL – Taprolano

+0

Nein, Nein, ich habe einfache Bilder .jpg von der URL – Taprolano

Antwort

1

sd_setImageWithURL: (nullable NSURL *) url

Die API ermöglicht die Nullable-Werte, so dass Sie beide müssen überprüfen, ob string und [NSURL URLWithString: string] Nicht-Null sind, bevor sie verwendet wird.

+0

yep. Ich löse dieses Problem, danke .. !! aber jetzt habe ich ein anderes Problem: Die Bilder werden gesehen, aber wenn ich auf ein Bild klicke, ändert es seine Größe und wird länger..Warum? Schauen Sie imgur.com/YhSUiBL – Taprolano

+0

Beitrag, den Inhalt von 'didSelectRowAt' Methode, und auch überprüfen, ob die UIImage hat jede IBAction/UIGestureRecognizer – nathan

+0

ok, neue Frage angebracht ist online..https: //stackoverflow.com/questions/45338779/the -width-of-images-in-uitableviewcell-Änderungen-zum-Klick – Taprolano

Verwandte Themen