English 中文(简体)
页: 1
原标题:iPhone: Object is null in another view when set with values read from XML
  • 时间:2011-08-10 22:16:41
  •  标签:
  • iphone

我阅读了一台XML,从一个角度对数据进行分类。 当我试图以另一种观点接触该物体时,该物体似乎是无效的。 先前的观点认为,国家航空航天局具有价值观。 我需要这些价值观,以形成一种 pick。 请让我知道我究竟是谁错了? 兹附上以下守则: 另一种观点认为,测试法的价值是无效的。

页: 1

NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version="1.0" encoding="utf-8"?>
"
                             "<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/">
"
                             "<soap:Body>
"
                             "<GetCommonCodeByCatg xmlns="http://longbeach.gov/PDPropertyReg/Services/">
"
                             "<catg>COLOR</catg>
"
                             "</GetCommonCodeByCatg>
"
                             "</soap:Body>
"
                             "</soap:Envelope>
"];
    NSLog(@"Soap Message%@",soapMessage);

    NSURL *url =[NSURL URLWithString:@"http://wwwbitdemo.longbeach.gov/PDPropertyReg/Services/CommonCode.asmx"];
    NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:url];
    NSString *msgLength =[NSString stringWithFormat:@"%d",[soapMessage length]];

    [theRequest addValue:@"text/xml; charset =utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:@"http://longbeach.gov/PDPropertyReg/Services/GetCommonCodeByCatg" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (theConnection) {
        webData = [[NSMutableData data]retain];
    }
    else {
        NSLog(@"The connection is null");
    }


}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    [webData setLength:0];
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

    [webData appendData:data];



}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    NSLog(@"Connection Error");
    [connection release];
    [webData release];



}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{

    NSLog(@"Done, Received bytes: %d",[webData length]);

    NSString *theXML =[[NSString alloc] initWithBytes:[webData mutableBytes]length:[webData length]encoding:NSUTF8StringEncoding];
    NSLog(@"XML value %@",theXML);
    [theXML release];

    if (xmlParser) {
        [xmlParser release];
    }

    xmlParser = [[NSXMLParser alloc]initWithData:webData];
    [xmlParser setDelegate:self];
    [xmlParser setShouldResolveExternalEntities:YES];
    [xmlParser parse];


    [connection release];
    index =0;

}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{



    if ([elementName isEqualToString:@"GetCommonCodeByCatgResult"]) {
        self.testArray = [[NSMutableArray alloc]init];
    }

    else if ([elementName isEqualToString:@"SvcCommonCode"]) {
        aCategory =[[Category alloc]init];
        if ([elementName isEqualToString:@"CMCode"]) {
        aCategory.CMCode = [attributeDict objectForKey:@"CMCode"];
        }
        NSLog(@"Reading the CMCode: %@",aCategory.CMCode);
    }

    NSLog(@"Processing element: %@", elementName);
}

-(void)parser: (NSXMLParser *)parser foundCharacters:(NSString *)string{

    if (!currentElementValue) 
        currentElementValue =[[NSMutableString alloc]initWithString:string];
        else 
            [currentElementValue appendString:string];

        NSLog(@"Processing value:%@",currentElementValue);





}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    if ([elementName isEqualToString:@"GetCommonCodeByCatgResult"]) {
        return;
    }
    if ([elementName isEqualToString:@"SvcCommonCode"]) {



        [self.testArray insertObject:aCategory atIndex:index];


        index =index+1;



        [aCategory release];
        aCategory =nil;
    }

    else 
        [aCategory setValue:currentElementValue forKey:elementName];

    [currentElementValue release];
    currentElementValue = nil;
    NSLog(@"Item count %i",[self.testArray count]);


}
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签