2012-04-20 18 views
1

我得到一個錯誤(當然它不顯示,剛剛崩潰了應用程序,在控制檯上沒有資料)發生 似乎每當我從RXML的rootXML調用該方法迭代:RaptureXML怪異的行爲

-(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並使用正常的非封裝樣式(//第一連接)我不會收到錯誤。但如果我使用第二個,當程序達到[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"); 

它正確顯示。

+0

我已經試着刪除信息搜索結果數組的分配(無論如何都會將其刪除),但沒有奏效。另外我想我只是注意到我可以消除「響應」,並直接調用我的自定義請求elementFromXMLData。但首先得解決這個錯誤! – Erakk 2012-04-20 14:01:15

+0

我個人更喜歡自己獲取xml(使用ASIHTTPRequest)並以字符串/數據的形式將它提供給xml解析器。之後,我使用TBXML(http://tbxml.co.uk/TBXML/TBXML_Free.html)作爲xml解析器,這只是一個偏好。 – Manuel 2012-04-20 14:02:07

+0

我在一箇舊項目中使用了TBXML,但正如你所說,偏好的事情......我開始使用RXML,它只是感覺平穩......直到這。 – Erakk 2012-04-20 14:38:04

回答

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]]; 
+0

我自己找到了,但那就是我必須要做的。謝謝。 – Erakk 2012-05-09 14:07:57

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

如果response是一個屬性使用self.response否則就會有內存泄漏問題。

+0

不解決我的主要錯誤,但幫助很多,謝謝! – Erakk 2012-04-20 14:36:53

+0

同樣適用於searchResult = [[NSMutableArray alloc] init]; 將其更改爲if(!self.searchResult)self.searchResult = [[[[NSMutableArray alloc] init] autorelease]; – graver 2012-04-20 14:39:22

+0

再次感謝graver – Erakk 2012-04-20 14:54:28