我尝试从soap加载数组并在tableview上显示数组成员。运行时出现此错误:
App[711:c07] Log Output:(null)
2013-06-05 13:18:58.198 App[711:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x1736012 0x1443e7e 0x16e9b6a 0x16e9a20 0x3a511 0xf23760 0x1c91685 0x1c934e5 0x1c92f07 0xf21e02 0x3a333 0xf49589 0xf47652 0xf4889a 0xf4760d 0xf47785 0xe94a68 0x223b911 0x223abb3 0x2278cda 0x16d88fd 0x227935c 0x22792d5 0x2163250 0x16b9f3f 0x16b996f 0x16dc734 0x16dbf44 0x16dbe1b 0x27977e3 0x2797668 0x387ffc 0x2add 0x2a05 0x1)
libc++abi.dylib: terminate called throwing an exception
我的数组:NSMutableArray *BranchesNameArray;
在这里调用 SOAP
NSString *mensagemSOAP= [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<GetBranches xmlns=\"http://tempuri.org/\">\n"
"<dt1>Africa</dt1>\n"
"</GetBranches>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
NSLog(@"SOAP Msg = \n%@\n\n", mensagemSOAP);
NSURL *url = [NSURL URLWithString:@"http://servis.com:1249/service.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; NSString *tamanhoMensagem = [NSString stringWithFormat:@"%d", [mensagemSOAP length]];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/GetBranches" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:tamanhoMensagem forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[mensagemSOAP dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conexao = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(conexao){
webData = [NSMutableData data];
}else{
NSLog(@"Connection Error.");
}
}
didStart 在这里
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ( [elementName isEqualToString:@"branchname"] ) {
NSLog(@"Log Output%@",[attributeDict objectForKey:@"branchname"]);
[BranchesNameArray addObject:[attributeDict objectForKey:@"branchname"]];
teveRetorno = YES;
}
didEnd 在这里
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:
(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ( [elementName isEqualToString:@"branchname"] ) {
[[self tableView]reloadData];
teveRetorno = NO;
}
}
表视图在这里
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
cell.textLabel.text =[BranchesNameArray objectAtIndex:indexPath.row];
return cell;
}