tags:

views:

358

answers:

4

How can i initialize selection bar in UIPickerview, when i run it, it shows ,first row is selected with bar..how can i change the row inwhich selection bar must be there dynamically?

i have done like following ...its not working?

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 

      {

     [psportPicker selectRow:3 inComponent:component animated:YES];
     return [citycount];


    }
+1  A: 
[picker selectRow:[self.pickerData indexOfObject:indexToSelect] inComponent:0 animated:NO];

See the UIPickerView Class Reference for details.

mahboudz
but the selection bar is in first row......any solution?
Mikhail Naimy
i have edited code pls...
Mikhail Naimy
You have to call [picker selectRow...]; in your viewDidLoad or not in one of the picker delegates.
mahboudz
A: 

Do you just want to select a certain row programmatically?

In that case, try -selectRow:inComponent:animated: (see the documentation for UIPickerView.

Thomas Müller
but the selection bar is in first row......any solution?
Mikhail Naimy
A: 

You need to call selectRow from viewDidAppear on the parent view controller. I encountered the same problem when I was calling selectRow from viewDidLoad. Move your selectRow into viewDidAppear and the UIPickerView will respond appropriately.

Cannonade
A: 

You can call selectRow from viewDidLoad after [super viewDidLoad] on the parent view controller. Your UIPickerView property should be properly initialized at that point.

Shiun