Search code examples
iosuipickerview

How to spin two components at a same time in uipickerview


It is my first app that I am trying to build in Iphone and I have some problems.I am using uipicker view in my app in which i am storing data coming from server. problem is that i have two components i want to spin both components at a same time not one by one.How it can done. below is code

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;


}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.jsonresultarr.count;


}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

    return [[self.jsonresultarr objectAtIndex:row] objectForKey:@"Company_Id"];

    return [[self.jsonresultarr objectAtIndex:row] objectForKey:@"Company_name"];





}

I want to move these two components at a same time ??


Solution

  • This can be more easily done by having a single section and displaying all of your information in that section formatted.

    To do that, return 1 in numberOfComponentsInPickerView (or omit that method as I believe the default is 1). In titleForRow, create a string that has the information from both of the keys.

    NSObject *companyId = [[self.jsonresultarr objectAtIndex:row] objectForKey:@"Company_Id"];
    NSObject *companyName = [[self.jsonresultarr objectAtIndex:row] objectForKey:@"Company_name"];
    return [NSString stringWithFormat:@"%@ %@", companyId, companyName, nil];