2017-03-29 11 views
0

enter image description here私はthis.codeのようなUIPickerviewを開発したいと思っています。単一のUIViewcontrollerのMultipleUIPickerViewの問題IOSアプリケーションの

データiがdifferantアレイ内にINDIVISUAL SOAP応答を追加し、PickerViewのタグに基づいた割り当てのために、私はthissee referance画像ようDevelopeするコードの上に使用
#import "CalcViewController.h" 

@interface CalcViewController() 

@end 

@implementation EZCalcViewController 

+(CalcViewController *)viewcontroller{ 
    CalcViewController *rz=[[CalcViewController alloc]initWithNibName:@"CalcViewController" bundle:nil]; 
    return rz; 
} 



- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    picker1 = [[UIPickerView alloc] init]; 
    [self.view addSubview:picker1]; 
    picker2 = [[UIPickerView alloc] init]; 
    [self.view addSubview:picker2]; 
    picker3 = [[UIPickerView alloc] init]; 
    [self.view addSubview:picker3]; 
    picker1.delegate=self; 
    picker1.delegate=self; 
    _customPickerArrayshap = [[NSMutableArray alloc] init]; 
    _customPickerArraycolor = [[NSMutableArray alloc] init]; 
    _customPickerArrayclarity = [[NSMutableArray alloc] init]; 

    /// [_customPickerArrayshap.count = 0]; 
    [self dropdownshape]; 
    [self dropdowncolor]; 
    [self dropdownclarity]; 


} 
-(void)dropdownshape 
{ 


    NSLog(@"dropdown method is call"); 

    NSString *envalope=[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" 
         "<value1 xmlns=\"http://tempuri.org/\">\n" 
         “</value1>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>"]; 

    envalope=[NSString stringWithFormat:envalope]; 
    NSData *envelope = [envalope dataUsingEncoding:NSUTF8StringEncoding]; 
    NSString *[email protected]“ABC.asmx"; 

    NSMutableURLRequest *request2 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 

    [request2 addValue:@"http://tempuri.org/Value1" forHTTPHeaderField:@"SOAPAction"]; 
    [request2 setHTTPMethod:@"POST"]; 
    [request2 setHTTPBody:envelope]; 
    [request2 setValue:@"text/xml; charset=utf-8" 
    forHTTPHeaderField:@"Content-Type"]; 
    [request2 setValue:[NSString stringWithFormat:@"%d", [envelope length]]forHTTPHeaderField:@"Content-Length"]; 

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request2 delegate:self]; 
    if (connection){ 
     resshap = [NSMutableData data]; 
     NSLog(@"connection Establish."); 
    } 
    else{ 
     NSLog(@"NSURLConnection initWithRequest: Failed to return a connection."); 
    } 

} 
-(void)dropdowncolor 
{ 


    NSLog(@"dropdown method is call"); 

    NSString *envalope=[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" 
         "<value2 xmlns=\"http://tempuri.org/\">\n" 
         “</value2>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>"]; 

    envalope=[NSString stringWithFormat:envalope]; 
    NSData *envelope = [envalope dataUsingEncoding:NSUTF8StringEncoding]; 
    NSString *[email protected]"http://ABC.asmx"; 

    NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 

    [request1 addValue:@"http://tempuri.org/value2" forHTTPHeaderField:@"SOAPAction"]; 
    [request1 setHTTPMethod:@"POST"]; 
    [request1 setHTTPBody:envelope]; 
    [request1 setValue:@"text/xml; charset=utf-8" 
    forHTTPHeaderField:@"Content-Type"]; 
    [request1 setValue:[NSString stringWithFormat:@"%d", [envelope length]]forHTTPHeaderField:@"Content-Length"]; 

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request1 delegate:self]; 
    if (connection){ 
     rescolor = [NSMutableData data]; 
     NSLog(@"connection Establish."); 
    } 
    else{ 
     NSLog(@"NSURLConnection initWithRequest: Failed to return a connection."); 
    } 

} 

-(void)dropdownclarity 
{ 


    NSLog(@"dropdown method is call"); 

    NSString *envalope=[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" 
         "<value3 xmlns=\"http://tempuri.org/\">\n" 
         “</value3>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>"]; 

    envalope=[NSString stringWithFormat:envalope]; 
    NSData *envelope = [envalope dataUsingEncoding:NSUTF8StringEncoding]; 
    NSString *[email protected]"http://ABC.asmx"; 

    NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 

    [request1 addValue:@"http://tempuri.org/value3" forHTTPHeaderField:@"SOAPAction"]; 
    [request1 setHTTPMethod:@"POST"]; 
    [request1 setHTTPBody:envelope]; 
    [request1 setValue:@"text/xml; charset=utf-8" 
    forHTTPHeaderField:@"Content-Type"]; 
    [request1 setValue:[NSString stringWithFormat:@"%d", [envelope length]]forHTTPHeaderField:@"Content-Length"]; 

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request1 delegate:self]; 
    if (connection){ 
     resclarity = [NSMutableData data]; 
     NSLog(@"connection Establish."); 
    } 
    else{ 
     NSLog(@"NSURLConnection initWithRequest: Failed to return a connection."); 
    } 

} 
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 

    [resshap setLength:0]; 
    [rescolor setLength:0]; 
    [resclarity setLength:0]; 
} 
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 

    [resshap appendData:data]; 
    [rescolor appendData:data]; 
    [resclarity appendData:data]; 

} 
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    NSLog(@"connection didFailWithError: %@ %@", error.localizedDescription, 
      [error.userInfo objectForKey:NSURLErrorFailingURLStringErrorKey]); 
    NSString *err=error.localizedDescription; 
    UIAlertView *alr=[[UIAlertView alloc]initWithTitle:@"App" message:err delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 

} 
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    // [[ActivityIndicator currentIndicator]displayCompleted]; 
    NSLog(@"DONE. Received Bytes:%d",[resshap length]); 
    NSLog(@"DONE. Received Bytes:%d",[rescolor length]); 
    NSLog(@"DONE. Received Bytes:%d",[resclarity length]); 

    NSString *theXml1 = [[NSString alloc] initWithBytes:[resshap mutableBytes] length:[resshap length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"The final result 1--- :%@",theXml1); 

    NSString *string1=[NSString stringWithFormat:@"r%@d",theXml1]; 
    NSLog(@"Object having value 1%@",string1); 

     NSString *thexml2 = [[NSString alloc] initWithBytes:[rescolor mutableBytes] length:[rescolor length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"The final result 2--- :%@",theXml1); 

    NSString *string2=[NSString stringWithFormat:@"r%@d",thexml2]; 
    NSLog(@"Object having value 2%@",string2); 

     NSString *thexml3 = [[NSString alloc] initWithBytes:[resclarity mutableBytes] length:[resclarity length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"The final result 3--- :%@",theXml1); 

    NSString *string3=[NSString stringWithFormat:@"r%@d",thexml3]; 
    NSLog(@"Object having value 3%@",string3); 


    if(xmlParser1) 
    { 

    } 
    xmlParser1 = [[NSXMLParser alloc] initWithData: resshap]; 
    [xmlParser1 setDelegate:self]; 
    [xmlParser1 setShouldResolveExternalEntities:YES]; 
    [xmlParser1 parse]; 
    //[theXml release]; 

    if(xmlParser2) 
    { 

    } 
    xmlParser2 = [[NSXMLParser alloc] initWithData: rescolor]; 
    [xmlParser2 setDelegate:self]; 
    [xmlParser2 setShouldResolveExternalEntities:YES]; 
    [xmlParser2 parse]; 
    //[theXml release]; 

    if(xmlParser3) 
    { 

    } 
    xmlParser3 = [[NSXMLParser alloc] initWithData: resclarity]; 
    [xmlParser3 setDelegate:self]; 
    [xmlParser3 setShouldResolveExternalEntities:YES]; 
    [xmlParser3 parse]; 
    //[theXml release]; 


} 


//} 
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *)attributeDict { 
    if([elementName isEqualToString:@“Value1Result"]) 
    { 
     if (!soapResults1) 
     { 
      soapResults1 = [[NSMutableString alloc] init]; 
     } 
     elementFound1 = YES; 
    } 
    else if([elementName isEqualToString:@“Value2Result"]){ 
     if (!soapResults2) 
     { 
      soapResults2 = [[NSMutableString alloc] init]; 
     } 
     elementFound2 = YES; 
    }else if([elementName isEqualToString:@“value3Result"]) 
    { 
     if (!soapResults3) 
     { 
      soapResults3 = [[NSMutableString alloc] init]; 
     } 
     elementFound3 = YES; 
    } 


} 
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string 
{ 
    if (elementFound1) 
    { 
     [soapResults1 appendString: string]; 



     NSArray * jsonarr1 =[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; 
     NSLog(@"print array :%@",jsonarr1); 
     for (NSDictionary * d in jsonarr1) 
     { 
      if ([d objectForKey:@"SHP"]!=[NSNull null]) 
      { 
       [picker1 reloadAllComponents]; 
       self.shapestring=[NSString stringWithFormat:@"%@",[d objectForKey:@“V1”]]; 
       NSLog(@"pVALUE FOR CLR :%@",self.shapestring); 
       [_customPickerArrayshap addObject:self.shapestring]; 
       NSLog(@"pVALUE AFTER ARRAY FILL:%d",_customPickerArrayshap.count); 
       [picker1 reloadAllComponents]; 
      } 
      else 
      {[email protected]""; 
          } 
     } 
    } 
     if(elementFound2){ 
      [soapResults2 appendString: string]; 



      NSArray * jsonarr2 =[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; 
      NSLog(@"print array :%@",jsonarr2); 
      for (NSDictionary * d in jsonarr2) 
      { 

      if ([d objectForKey:@"RAPCOL"]!=[NSNull null]) 
      { 
       [picker2 reloadAllComponents]; 
       self.colorstring=[NSString stringWithFormat:@"%@",[d objectForKey:@“v2”]]; 
       NSLog(@"pVALUE FOR CLR :%@",self.colorstring); 
       [_customPickerArraycolor addObject:self.colorstring]; 
       // NSLog(@"pVALUE AFTER ARRAY FILL:%d",_customPickerArray1.); 
       [picker3 reloadAllComponents]; 
      } 
      else 
      { 
       [email protected]""; 

      } 

     } 
     } 
     if(elementFound3){ 
      [soapResults3 appendString: string]; 

      NSArray * jsonarr3 =[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; 
      NSLog(@"print array :%@",jsonarr3); 

      for (NSDictionary * d in jsonarr3) 
      { 

      if ([d objectForKey:@"CLR"]!=[NSNull null]) 
      { 
       [picker3 reloadAllComponents]; 
       self.claritystring=[NSString stringWithFormat:@"%@",[d objectForKey:@“V3”]]; 
       NSLog(@"pVALUE FOR CLR :%@",self.claritystring); 
       [_customPickerArrayclarity addObject:self.claritystring]; 
       // NSLog(@"pVALUE AFTER ARRAY FILL:%d",_customPickerArray1.); 
       [picker3 reloadAllComponents]; 
      } 
      else 
      { 
       [email protected]""; 
      } 

     } 
     } 
    } 


-(void)parser:(NSXMLParser *)parser 
didEndElement:(NSString *)elementName 
namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName 
{ 
    if ([elementName isEqualToString:@“value1Result"]) 
    { 


     [self.customPickerArrayshap addObject:@“v1”]; 

     NSLog(@"%@",soapResults1); 

     [soapResults1 setString:@""]; 
     elementFound1 = FALSE; 

    } 
    else if ([elementName isEqualToString:@“Value2Result"]) 
    { 


     [self.customPickerArraycolor addObject:@“v2”]; 
      [soapResults2 setString:@""]; 
     elementFound2 = FALSE; 

    }else if ([elementName isEqualToString:@“Value3Result"]){ 
     [self.customPickerArrayclarity addObject:@“V3”]; 
      [soapResults3 setString:@""]; 
     elementFound3 = FALSE; 
    } 



} 
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1; 
} 
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 

    if([pickerView tag]==1) 
    { 
     return _customPickerArrayshap.count; 
    } 
    else if([pickerView tag]==2) 
    { 

     return _customPickerArraycolor.count; 
    }else if([pickerView tag]==3){ 


     return _customPickerArrayclarity.count; 
    } 


} 
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    if([pickerView tag]==1) 
    { 

     return _customPickerArrayshap[row]; 
    } 
    else if([pickerView tag]==2) 
    { 
     return _customPickerArraycolor[row]; 
    }else if([pickerView tag]==3){ 
     return _customPickerArrayclarity[row]; 
    } 

} 

は、私は、3 PickerViewを有しており、データは石鹸Webサービスから設定されています値のデータが割り当てられますが、問題は最初の石鹸応答がpickerviewで割り当てられているだけです。残りの2つはnullです。間違っている場合は、私に提案してください。

答えて

0

あなたがのviewDidLoadで{

  • (無効)のviewDidLoadを[最初のサービスを呼び出します

    [self dropdownshape]; 
    
    [self dropdowncolor]; 
    
    [self dropdownclarity]; 
    

    代わりにその時に3つのWebサービスを呼び出していますスーパービューDidLoad];

    [self dropdownshape];

}

その最初の接続は、(接続){

resshap = [NSMutableDataデータ]場合は

第二のウェブサービスを呼び出すことができることで確立された後。

[self dropdowncolor];そして、第二の接続は、それはあなた

に役立つだろうチェックリンクの下(接続){

rescolor = [NSMutableData data]; 

[self dropdownclarity]; 

} 

場合は、第3ウェブサービス

を呼び出すことができるということで設立された

}

- (void)接続:(NSURLConnection *)接続didReceiveResponse:(NSURLResponse *)応答 {

if(connection == connection1) { 

    //Do something with connection 1 

} 

else if(connection == connection2) { 

    //Do something with connection 2  

} 

(接続== connection3){

//Do something with connection 3 

} 

}

https://stackoverflow.com/a/6434433/5184217

NOTE他の場合:

-1
Try 

picker1.delegate=self; 
picker1.tag = 1; 

picker2.delegate=self; 
picker2.tag = 2; 

picker3.delegate=self; 
picker3.tag = 3; 
+0

OK未テスト、私は「この – Rucha

+0

ことができますしようとしています私の問題を解決しないでください – Rucha

+0

@Rucha、plzは更新された答えを確認します。タグの割り当てがありません。 –

関連する問題