tags:

views:

434

answers:

4

Hi

I am having to picker controls on a single view with two outlets for each. Now when I select any of them same delegate methods are get called. How should we distinguish between which picker control has called the delegate ? Another question is can we change the frame size of the pickers to fit in one view?

Thanks Amit

A: 

Two pickers in a view sounds crazy ugly. Would it really not work for you to have a picker with two components (ie, columns)?

Nevertheless, the first parameter in every method defined by UIPickerViewDelegate is the picker that called you. If you have wired an IBOutlet to each UIPickerView, then you should be able to compare this parameter to those outlets to figure out which one has called you. Something like this:

IBOutlet UIPickerView *fooPicker;
IBOutlet UIPickerView *barPicker;

// ...

- (NSString *)pickerView:(UIPickerView *)pickerView
    titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (pickerView == fooPicker)
         return [NSString stringWithFormat @"Foo row %d", row];
    else 
         return [NSString stringWithFormat @"Bar row %d", row];
}

It might be cleaner to connect to different objects as your delegates, but with two pickers in one view, "clean" probably isn't an option for you anyways.

invalidname
The problem is the data to be shown in both the prickers is big inough to be adjusted . So when we do that the text get trimmed off with "..." and I think we can not reduce the font size of the text inside pickers?
Amit Jain
A: 

Set the view to a UILable and set the font size or adjustsFontSizeToFitWidth:

UILabel *myView;
myView = [[[UILabel alloc] initWithFrame:myFrameRect] autorelease];
myView.adjustsFontSizeToFitWidth = YES;
return myView;
zaph
A: 

I've had great success with putting two pickers right on top of one another and then using a UISegmentedControl to select which is visible, by setting the .hidden properties of each.

Birdlevitator
A: 

Instead of having two picker, you can make it as one. You can have the picker controller in a view . Once the user touch a button rise up the view and make them to select from the picker and remove the view.This will reduce the space in the Main viewcontroller.

Senthil