Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I have a problem related to scrolling multiple components of UIPickerView. I created uipickerview with two components but when i scroll one of them, other also scroll but after part of second.

Code :

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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
       return [finalArray count];
}


-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0) {
    return [[finalArray objectAtIndex:row] objectForKey:@"value1"];
}else if (component == 1){
    return [[finalArray objectAtIndex:row] objectForKey:@"value2"];
}else{
    return nil;
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
        [thePickerView selectRow:row inComponent:0 animated:NO];
        [thePickerView selectRow:row inComponent:1 animated:NO];
}

What i want is scrolling any components should scroll all together just like it is only one. It should not show even part of second for auto scrolling.

If it is possible, what do you recommend to do?...

share|improve this question
4  
If you want both to scroll together, what is the purpose of making two components? –  Anupdas May 23 '13 at 8:32
    
For making better alignment.. I have tried with one component but i didn't get the way to put multiple lables in a row with better alignment.. i want effect like when pickerview have more component.. –  MehulS May 23 '13 at 8:53

1 Answer 1

up vote 0 down vote accepted

Oke I got the solution with comment of Anupdas ...

By giving number of spaces i get solution to my problem.

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    __weak NSString *lbl1 = [NSString stringWithString:[[finalArray objectAtIndex:row] objectForKey:@"value1"]];
    lbl1 = [lbl1 stringByAppendingString:@"                                            "];
    lbl1 = [lbl1 stringByAppendingString:[[finalArray objectAtIndex:row] objectForKey:@"value2"]];
    return lbl1;
}
share|improve this answer
1  
Glad to know that you found a solution. You can also use pickerView:viewForRow:forComponent:reusingView: If you want to customize further. –  Anupdas May 23 '13 at 9:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.