加载图像在我的RSS提要应用程序,我通过输入didStartElement方法解析用的NSXMLParser图片:SDWebImage不会从URL中的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);
}
而在didEndElement方法:
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]];
}
好的。这工作,我拥有他们所有的链接。
现在我想将这些URL加载到我的UITableView中的单元格中。所以我使用了'SDWebImage'窗格。
cellForRowAtIndexPath方法中我有:
- (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;
}
但没有发生。这是我目前的情况。
如何解决?
你能打印'字符串的值和'[NSURL URLWithString:string]'值吗?该网址可能不是 – nathan
@nathan yep。我解决了这个问题,但现在我又遇到了另一个问题:可以看到图像,但是当我点击一张图像时,它会改变它的大小并变得更长。为什么?看看http://imgur.com/YhSUiBL – Taprolano
不,不,我有简单的图片.jpg来自url – Taprolano