iPhone SDK - 问题从RSS提要中解析XML

时间:2010-09-10 17:09:40

标签: iphone xml parsing rss

我制作了一个RSS阅读器,可以从blogspot获取提要。 故事,标题等文字工作正常。 但是在Feed中发布的图像显示为链接而不是图像。 如何显示图像?

1 个答案:

答案 0 :(得分:1)

以下是我用于将图像动态下载到列表中的一些代码:

//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];
}

希望它有所帮助,祝你好运!