1

RXMLのrootXMLからIterateメソッドを呼び出すたびに発生するように見えるエラー(表示されない、アプリからクラッシュするだけ、コンソールに情報がない)が発生します。

-(void)valueSearch {
    //FIRST CONNECTION
    NSString *serverAddress = @"http://www.commix.com.br/clientes/grupoglobo/apple/valor.xml";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress] 
                                                       cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                   timeoutInterval:10];
NSError *requestError;
    NSURLResponse *urlResponse = nil;

    response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];

    //SECOND CONNECTION - Just an encapsulated form of the first, since i use it in other parts
    // of the code
    response = [self requestWithParameters:@"valor.xml"];

    //i just uncommented both. but actually only one (connection) runs.

    //Creation of the rooXML so i can grab the info i need
    RXMLElement *rootXML = [RXMLElement elementFromXMLData:response];
    //This array is where i'll keep the info from the files.
    //it`s deallocated at the end in dealloc
    searchResult = [[NSMutableArray alloc] init];

    //This is the culprit. Atleast it seems so, since putting NSLog before and after
    //revealed so.
    [rootXML iterate:@"valor" usingBlock: ^(RXMLElement *valor) {
        NSLog(@"valor: %@", [valor child:@"nome"].text);
        [searchResult addObject:[valor child:@"nome"].text];
    }];
}

コメントしてrequestWithParameters、通常のカプセル化されていないスタイル(// FIRST CONNECTION)を使用しても、エラーは発生しません。しかし、2番目を使用すると、プログラムが到達すると、[rootXML iterate: [...]]警告なしにクラッシュします。

RaptureXMLの使用:https ://github.com/ZaBlanc/RaptureXML

これは、コードの別の部分でも発生します。

-(void)vehicleSearch {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"idArray" ofType:@"plist"];
    NSMutableArray *idArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

    NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress] 
                                                       cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                   timeoutInterval:10];

NSError *requestError;
    NSURLResponse *urlResponse = nil;
    response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];

    RXMLElement *rootXML = [RXMLElement elementFromXMLData:response];
    searchResult = [[NSMutableArray alloc] init];

    [rootXML iterate:@"modelo" usingBlock: ^(RXMLElement *modelo) {
        NSLog(@"modelo: %@", [modelo child:@"nome"].text);
        [searchResult addObject:[modelo child:@"nome"].text];
    }];

    [idArray release];
}

同じ行で発生し[rootXML iterate:]ます。

リークなどでごめんなさい、私は経験が浅いです(だから私はここにいます)、ありがとう!

編集:実際には、犯人は行です

NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]);

変数なしでパラメーターを直接渡すと、次のように機能します。

NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=4");

正しく表示されます。

4

2 に答える 2

1
response = [self requestWithParameters:@"valor.xml"];

ifresponseはプロパティの使用self.responseです。そうしないと、メモリ リークの問題が発生します。

于 2012-04-20T14:03:13.063 に答える
1

,[idArray objectAtIndex:0]それが NSStringであると確信していますか? 使ってみて

[NSString stringWithFormat:@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]];` 

あるいは

[NSString stringWithFormat:@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[[idArray objectAtIndex:0]stringValue]];
于 2012-04-21T11:52:23.303 に答える