http://www.cinejosh.com/news/3/40889/high-court-dismisses-andhra-poris-case.html
在上面的链接中我有这个标签
<img src="/newsimg/newsmainimg/1433410900_andhra-pori.jpg" alt="High Court Dismisses 'Andhra Pori's Case" class="img-responsive center-block visible-xs">
我有上面的标签,我需要在imageview上获取图像。
我的代码就像这样
NSString *gossipsXpathQueryString = @"//td//img";
//imageGossipsNodes is the array to get data
imageGossipsNodes = [gossipsParser searchWithXPathQuery:gossipsXpathQueryString];
for (TFHppleElement *element in imageGossipsNodes)
{
NSString *imageUrlString = [NSString stringWithFormat:@"http://www.cinejosh.com%@", [element objectForKey:@"src"]];
}
现在我想通过字符串获取图片。如何实现这一目标?请帮助我。
谢谢
答案 0 :(得分:0)
您有两个选项同步和异步选项。尝试使用异步方法。
UIImage *image = [UIImage imageWithContentsOfURL:[NSURL URLWithString:imageUrlString];
yourImageView.image = image;
或
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:imageUrlString];
UIImage *image = [UIImage imageWithData: data];
dispatch_async(dispatch_get_main_queue(), ^{
yourImageView.image = image;
});
});