我得到一个错误(当然它不显示,刚刚崩溃了应用程序,在控制台上没有资料)发生 似乎每当我从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");
它正确显示。
我已经试着删除信息搜索结果数组的分配(无论如何都会将其删除),但没有奏效。另外我想我只是注意到我可以消除“响应”,并直接调用我的自定义请求elementFromXMLData。但首先得解决这个错误! – Erakk 2012-04-20 14:01:15
我个人更喜欢自己获取xml(使用ASIHTTPRequest)并以字符串/数据的形式将它提供给xml解析器。之后,我使用TBXML(http://tbxml.co.uk/TBXML/TBXML_Free.html)作为xml解析器,这只是一个偏好。 – Manuel 2012-04-20 14:02:07
我在一个旧项目中使用了TBXML,但正如你所说,偏好的事情......我开始使用RXML,它只是感觉平稳......直到这。 – Erakk 2012-04-20 14:38:04