2017-03-28 23 views
0
In my Application I have 3 UIPickerView and data is added using soap web service,response is getting ok but can't add in picker view,i'm new for objectives programming,please suggest me. 

here I post some code. 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    picker1 = [[UIPickerView alloc] init]; 
    [self.view addSubview:picker1]; 
    _customPickerArray1 = [[NSMutableArray alloc] init]; 
    [self dropdown]; 
} 
-(void)dropdown 
{ 
    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" 
         "<Value xmlns=\"http://tempuri.org/\">\n" 
         「</Value>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>"]; 

    envalope=[NSString stringWithFormat:envalope]; 
    NSData *envelope = [envalope dataUsingEncoding:NSUTF8StringEncoding]; 

    NSString *url = @「ABC.asmx"; 

    NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];  
} 
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *)attributeDict { 
    if([elementName isEqualToString:@「ValueResult"]) 
    { 
     if (!soapResults) 
     { 
      soapResults = [[NSMutableString alloc] init]; 
     } 
     elementFound = YES; 
    } 


} 
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string 
{ 
    if (elementFound) 
    { 
     [soapResults appendString: string]; 
     NSArray * jsonarr =[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; 
     NSLog(@"print array :%@",jsonarr); 
     for (NSDictionary * d in jsonarr) 
     { 
      if ([d objectForKey:@"CLR"]!=[NSNull null]) 
      { 
       self.colorstring=[NSString stringWithFormat:@"%@",[d objectForKey:@"CLR"]]; 
       NSLog(@"pVALUE FOR CLR :%@",self.colorstring); 
       [_customPickerArray1 addObject:self.colorstring]; 
       NSLog(@"pVALUE AFTER ARRAY FILL:%d",_customPickerArray1.count); 

      } 
      else 
      { 
       [email protected]""; 
      } 
     } 
    } 
} 
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 3; 
} 

// The number of rows of data 
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 

    if([pickerView tag]==1) 
    { 

     return _customPickerArray1.count; 
    } 
    else if([pickerView tag]==2) 
    { 
     return _customPickerArray1.count; 
    }else if([pickerView tag]==3){ 
     return _customPickerArray1.count; 
    } 
} 
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    if([pickerView tag]==1) 
    { 

     return _customPickerArray1[row]; 
    } 
    else if([pickerView tag]==2) 
    { 
     return _customPickerArray1[row]; 
    }else if([pickerView tag]==3){ 
     return _customPickerArray1[row]; 
    } 
    } 
@end 

首先我在廈門國際銀行,並設置數據源和委託申報3選擇器視圖,並在後臺SOAP網絡服務是要求在pickerview添加數據,但SOAP響應成功回來,但肥皂響應也在NSMutablearray中設置,但不能在選擇器視圖中表示。多UIPickerview不能添加SOAP響應

+0

嘗試重新加載pickerview比檢查 – iOS

回答

0

當你得到響應,並通過parser解析它寫相應的picker重載方法,這樣你會得到所有datasource方法調用和數據都將在各自的picker填寫。

[picker reloadAllComponents]; 

希望這會有所幫助。

+1

是的,它解決了我的問題,謝謝 – Rucha