いくつかの画像を含む xml があり、グリッド ビューで画像を表示する必要があります。画像の URL を解析できますが、グリッド ビューを表示している間は、xml の最後の画像しか表示されません。以下のコードがあります。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
if(nil != qualifiedName){
elementName = qualifiedName;
}
if ([elementName isEqualToString:@"images"]) {
self.ixml = [[ImageObj alloc]init];
}
else if([elementName isEqualToString:@"image"] )
{
self.currentElement = [NSMutableString string];
} else {
self.currentElement = nil;
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if(nil != qName){
elementName = qName;
}
if([elementName isEqualToString:@"image"]){
self.ixml.imageName=self.currentElement;
NSLog(@"data %@",self.currentElement);
}
else if([elementName isEqualToString:@"images"]) {
[[self imagerssItems] addObject:self.ixml];
NSLog(@"self ixml %@",self.ixml);
NSLog(@"self %@",imagerssItems);
}
}
すべてのURLがログインに表示されていますNSLog(@"data %@",self.currentElement);
が、次の行に表示されています
NSLog(@"self ixml %@",self.ixml);
NSLog(@"self %@",imagerssItems);
1 つの要素のみが設定されていることを示しています。
ここで何かを見逃していますか?ガイダンスが役立ちます。
ありがとうございました。
編集
以下のようなxml形式があります-
<images>
<image>link here</image>
<image>link here</image>
<image>link here</image>
</images>
解析手順は正しいですか?