1
xlmリーダーに問題があります。私は配列で在庫したいいくつかの通貨ライダーを持っていますが、私のコードでは間違っています。ここで目的c xmlを読み込み、配列に格納する
は私が読みたいフィードです: http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
ヘッダファイル
@class Convertisseur;
@interface Convertisseur1ViewController :
UIViewController <UITextFieldDelegate>{
IBOutlet UILabel *usd;
IBOutlet UILabel *euro;
Convertisseur *convertisseur;
// parser XML
NSXMLParser *rssParser;
// elenco degli elementi letti dal feed
NSMutableArray *elencoFeed;
//variabile temporanea pe ogni elemento
NSMutableDictionary *item;
// valori dei campi letti dal feed
NSString *currentElement;
NSMutableString *currentCube;
NSArray *currency;
}
//Dichiarazion del parser
- (void)parseXMLFileAtURL:(NSString *)URL;
@end
実装ファイル
#import "Convertisseur1ViewController.h"
#import "Convertisseur.h"
@implementation Convertisseur1ViewController
- (void)parseXMLFileAtURL:(NSString *)URL {
// inizializziamo la lista degli elementi
elencoFeed = [[NSMutableArray alloc] init];
// dobbiamo convertire la stringa "URL" in un elemento "NSURL"
NSURL *xmlURL = [NSURL URLWithString:URL];
// inizializziamo il nostro parser XML
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
// settiamo alcune proprietà
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
// avviamo il parsing del feed RSS
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// inizializza tutti gli elementi
item = [[NSMutableDictionary alloc] init];
currentCube = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"Cube"]) {
/* salva tutte le proprietà del feed letto nell'elemento "item", per
poi inserirlo nell'array "elencoFeed" */
[item setObject:currentCube forKey:@"Cube"];
[elencoFeed addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{;
// salva i caratteri per l'elemento corrente
if ([currentElement isEqualToString:@"Cube"]){
[currentCube appendString:string];
}
}
- (void) parserDidEndDocument:(NSXMLParser *)parser {
for(int i=1;i<[elencoFeed count];i++) {
[currency setvalue:[[elencoFeed Objectatindex:i] valueforkey:@"rate"] forkey:[[elencoFeed Objectatindex:i] valueforkey:@"currency"]];
//currency[i]= [elencoFeed Objectatindex:i] valueforkey:@"rate"] forkey:[[elencoFeed Objectatindex:i] valueforkey:@"currency"];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
convertisseur = [[Convertisseur alloc] init];
self.title = @"Convertisseur";
NSString *path = @"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
[self parseXMLFileAtURL:path];
euro.text = currency.text;
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.labelEuro = nil;
self.labelDollar = nil;
self.convertisseur = nil;
}
- (void)dealloc {
[super dealloc];
}
書式設定されたコードは、質問を読むのをより簡単にします – Abizern
何が問題になりますか?あなたが得るかもしれないエラーメッセージを投稿できますか? –
エラーはここにあります:euro.text = currency.text; – Michele