0

私の問題が何であるかを簡単に説明しようとします...

XMLファイルを(touchXMLを使用して)ロードして、UITableViewにデータを入力しています。

expositions = [[NSMutableArray alloc] init];

// Get XML string from XML document.
NSString *xmlURL = EXPOSITION_XML_DOC;
NSString *xmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:xmlURL]];
NSString *xmlStringUTF8 = [NSString stringWithUTF8String:[xmlString UTF8String]];
CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithXMLString:xmlStringUTF8 options:0 error:nil];

// Parse XML document.
NSArray *expos = [xmlDoc  nodesForXPath:@"/expositions/exposition" error:nil];

if (expos != nil && [expos count] >= 1)
{
    // create Exposition instances with data from xml file
    for (CXMLElement *expo in expos)
    {
        NSString *date = [[[[expo attributeForName:@"date"] stringValue] copy] autorelease];
        NSString *name = [[[[expo attributeForName:@"name"] stringValue] copy] autorelease];
        NSString *place = [[[[expo attributeForName:@"place"] stringValue] copy] autorelease];
        NSLog(@"hello , %@, %@, %@", date, name, place);

        Exposition *e = [[Exposition alloc] initWithDate:date name:name place:place];
        [expositions addObject:e];
        NSLog(@"%@", e.name);
    }
}

for ループの最後で、渡されたばかりのデータの一部が出力され、解析された XML データを返す NSLog で正常に動作することがわかります。

しかし、配列にアクセスしようとすると

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

そのようです...

// get exposition data for this row
    Exposition *e = [expositions objectAtIndex:indexPath.row];

    NSString *str = e.name;
    NSLog(@"%@", str);

エラーが出ます!そして、私はその理由を理解していません。解析した XML データにドイツ語のウムラウトがいくつかありますが、UTF-8 エンコーディングを定義したので、これは問題になりません。しかし、もしそうなら、私に修正を教えてください。または、他に問題がある可能性があります...

4

2 に答える 2

0

Exposition *eメソッドで変数を再宣言していると思いますcellForRowAtIndexPath。その変数を .h ファイルで宣言します。

于 2010-02-01T13:29:57.947 に答える
0

今使ったばかりNSXMLParserで、ウムラウトを使用してもすべて正常に動作します。

いずれにしても XML ファイルはファイル サイズが小さいため、touchXML ライブラリと比較した場合のパフォーマンスはそれほど重要ではありません。

助けようとした人々への感謝。

于 2010-02-06T23:16:55.327 に答える