我制作了一个 RSS 阅读器,可以从 blogspot 获取提要。 故事、标题等文字效果很好。 但提要中发布的图像显示为链接而不是图像。 如何显示图像?
最佳答案
这是我用来动态下载图像到列表中的一些代码:
//starts the downloading of the image
- (void) downloadImage
{
[NSThread detachNewThreadSelector:@selector(imageDownloadWorker:)
toTarget:self
withObject:[self getAvatarUrl]/*here goes your url*/];
}
//does something with the image once loaded
- (void)imageLoaded:(UIImage *)image
{
//do something
}
//downloads the image
- (void)imageDownloadWorker:(NSString *)urlString
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
[self performSelectorOnMainThread:@selector(imageLoaded:)
withObject:[image autorelease]
waitUntilDone:YES];
[pool drain];
}
希望对你有帮助,祝你好运!
关于iPhone SDK - 从 RSS feed 解析 XML 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3686686/