2017-03-29 1 views
0

enter image description here dans IOS Application Je veux développer UIPickerview comme ceci.code est ci-dessous.Problème avec MultipleUIPickerView dans un seul UIViewcontroller

#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]; 
    } 

} 

utilisant code ci-dessus que je veux développer comme thissee l'image referance, j'ai 3 PickerView et les données sont définies à partir WebService de savon, pour les données affecter j'ai ajouter une réponse de savon Indivisual dans dans le tableau differant, et basé sur l'étiquette de PickerView données de valeur est assigner, mais le problème est que seule la première réponse de savon est assigner dans la sélection restante 2 sont nulles, s'il vous plaît me suggérer si je me trompe.

Répondre

0

Vous appelez 3 services Web à un moment

[self dropdownshape]; 

[self dropdowncolor]; 

[self dropdownclarity]; 

Au lieu de cela vous appellerez le premier service dans viewDidLoad

  • (void) viewDidLoad {

    [ super viewDidLoad];

    [self dropdownshape];

}

après Première connexion est établie dans ce que vous pouvez appeler deuxième service Web

si (connexion) {

resshap = [données NSMutableData];

[self dropdowncolor];

}

Ensuite, deuxième connexion est établie dans que vous pouvez appeler troisième service Web

si (connexion) {

rescolor = [NSMutableData data]; 

[self dropdownclarity]; 

} 

Vérifiez lien ci-dessous, il sera utile pour vous

- (void) connexion: (NSURLConnection *) connexion didReceiveResponse: (NSURLResponse *) réponse {

if(connection == connection1) { 

    //Do something with connection 1 

} 

else if(connection == connection2) { 

    //Do something with connection 2  

} 

else if (connexion == connection3) {

//Do something with connection 3 

} 

}

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

NOTE: Non testé

-1
Try 

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

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

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

ok, je vais essayer cette – Rucha

+0

il peut » t résoudre mon problème – Rucha

+0

@Rucha, plz vérifier la réponse mise à jour. Il vous manque des tags d'attribution. –