วิธีแสดงรูปภาพจากไฟล์ xml ใน UI Image View [ซ้ำกัน]

รายการซ้ำที่เป็นไปได้:
วิธีแสดงรูปภาพจากไฟล์ xml ใน UI Image View

ฉันมีไฟล์ 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(@"%@",อาร์เรย์); มันแสดง URL รูปภาพทั้งหมดในคอนโซลเอาต์พุต ฉันแค่ต้องแสดงมันบน UIImage ในไฟล์ nib ฉันไม่สามารถทำเช่นนั้นได้ ดังนั้นเมื่อคุณคลิกปุ่ม รูปภาพทั้งหมดควรแสดงในมุมมองแบบเลื่อน


person raptor85    schedule 04.11.2011    source แหล่งที่มา
comment
คำถามนี้มีรายละเอียดเพิ่มเติม แต่คุณควรแก้ไขต้นฉบับแทน   -  person jrturton    schedule 04.11.2011


คำตอบ (1)


การใช้ไลบรารี SDWebManager อาจช่วยคุณได้ https://github.com/rs/SDWebImage

ซึ่งจะช่วยในการดาวน์โหลด URL แบบอะซิงโครนัส จากนั้นคุณสามารถใช้เมธอด imageView setImageWithURL:

person elprl    schedule 04.11.2011