我收到一个错误(它没有显示,只是从应用程序中崩溃,控制台上没有信息),每当我从 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)时,我没有收到错误。但是如果我使用第二个,当程序到达时[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");
它显示正确。