2011-11-04 131 views
0

可能重复:
How to display images from an xml file in UI Image View如何在UI图像视图显示从XML文件中的图像

我有一个XML文件,也有子类别的图像的数量,我想 要在“图像视图”中显示所有图像,并且“图像视图”将在滚动视图中滚动视图,因为您需要继续加载图像。我是 编码有困难。下面的代码给了我url 链接,但我很难在'图像 视图'上显示图像,该图像可以使用“ScrollView”滚动。我还在显示 xml文件,其中显示产品

/////// XML文件////

<product> 
     <product_name>HRC Classic Pin Collector Bag Blk &#x2013; Hard Rock</product_name> 
     <url>http://rockshop.hardrock.com/PinsCollectibles/Pins/Product/HRC Classic Pin Collector Bag Blk/?src=sli</url> 
     <image>http://rockshop.hardrock.com/ProductImages/HRC Classic Pin Collector Bag Blk.1.jpg?w=177</image> 
     <large_image>http://rockshop.hardrock.com/ProductImages/HRC Classic Pin Collector Bag Blk.1.jpg?w=350</large_image> 
     <front_image>http://rockshop.hardrock.com/ProductImages/HRC Classic Pin Collector Bag Blk.1.jpg?w=80</front_image> 
     <product_number>HRC Classic Pin Collector Bag Blk</product_number> 
     <availability>1</availability> 
     <long_des>HRC Classic Pin Collector Bag Blk</long_des> 
     <launch_date>4/15/2011 10:49:54 AM</launch_date> 
     <price>40</price> 
     <category>Pins &amp; Collectibles</category> 
     <sub_category>Pins</sub_category> 
    </product> 

这里是代码

-(IBAction)downloadImages:(id)sender 
{ 
    NSData *data = [NSData dataWithContentsOfFile:@"pathOfURL"]; 
    NSError *error = nil; 
    GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error]; 
    NSError *err=nil; 
    NSArray *nodes = [document nodesForXPath:@"/product_list/product[category = \"Pins & Collectibles\"]/image" error:&err]; 
    NSMutableArray *array =[[NSMutableArray alloc]initWithCapacity:[nodes count]]; 

    for(int i=0;i<[nodes count]; i++) 
    { 
     [array addObject:(NSString *)[[(NSString *)[[(NSString *)[[[NSString stringWithFormat:@"%@",[nodes objectAtIndex:i]] componentsSeparatedByString:@"{"] objectAtIndex:1] componentsSeparatedByString:@"<image>"] objectAtIndex:1] componentsSeparatedByString:@"</image>"] objectAtIndex:0] ]; 
    } 

    NSLog(@"%@",array); 

} 

NSLog(@“%@”,array);它显示在输出 控制台中的所有图像url我只需要显示它们在UIImage中的笔尖文件,我不是 能够做到这一点,所以当你点击一个按钮时,所有的图像应该在滚动视图中显示 。

+0

在这个问题中有更多的细节,但你应该编辑原来的。 – jrturton

回答

0

使用SDWebManager库可能会对您有所帮助。 https://github.com/rs/SDWebImage

这将有助于异步下载的URL,然后你可以使用imageView的setImageWithURL:方法。