我收到错误消息(它不会显示,只是崩溃退出应用程序,控制台上没有任何信息)
每当我从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");
它显示正确。
最佳答案
您确定,[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]];