2011-06-23 47 views
0

我很新的iPhone开发。我试图实现滚动视图与动态从网页加载图像。我试图使用下面的代码。我怎样才能动态滚动图像

for (counter = 0; counter < 2; counter++) { 
    RSSEntry *entry = [_allEntries objectAtIndex:counter]; 
    NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: entry.articleUrl]]; 
    UIImage *img = [UIImage imageWithData: imageData]; 
    NSLog(@"%@", entry.articleUrl); 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:img]; 
    [imageData release]; 
    CGRect rect = scrollViewController.frame; 
    imageView.frame = rect; 
    imageView.tag = (counter + 1); // tag our images for later use when we place them in serial fashion 
    [scrollViewController addSubview:imageView]; 
    [imageView release]; 
} 

这些是我加载在viewDidLoad上的两幅图像。我想在用户滚动到第二张图片时加载下一张图片,并且如果用户滚动接下来要显示图像正在加载。任何建议?

回答

1

您可以使用NSURLConnection并异步下载图像。您可以使用TCImageView

https://github.com/totocaster/TCImageView

它下载的图像以异步方式。

我也推荐Three20的TTImageView。

+0

'TCImageView'刚刚更新并重命名为'TCWebImageView':https://github.com/totocaster/TCWebImageView –

相关问题