View Full Version : Set a UIPickerView row when loading a View? HOW?
ethana
Aug 11, 2008, 04:27 AM
How do I set a UIPickerView row when loading a View? I've tried but it's just not working. The row is always set to 0 when the View appears. By the way, I call "self" because I set the View to be the <UIPickerViewDelegate>.
Here's what my code is currently:
- (void)viewWillAppear:(BOOL)animated {
[self selectRow:2 inComponent:0 animated:YES];
}
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated {
[self reloadAllComponents];
}
- (void)reloadAllComponents {
}
Please help!
Thanks.
Ethan
robbieduncan
Aug 11, 2008, 05:53 AM
self is a pointer to the object that method belongs to. So if your object is not the UIPickerView or subclass then this won't work. You need a pointer to the UIPickerView instance.
ethana
Aug 11, 2008, 11:15 AM
How do I get the instance of it? I just dragged it over on Interface Builder, so it's not like I created it programmatically.
DipDog3
Aug 11, 2008, 11:18 AM
You need to add an instance variable to your View Controller file to start.
robbieduncan
Aug 11, 2008, 11:19 AM
Well if you are using IB then you'd add an outlet to the class and connect that to the picker.
ethana
Aug 11, 2008, 01:27 PM
I've tried both creating an instance of the View Controller as well as creating an Outlet for the PickerView and then making an instance of that, but neither has worked.
Can someone post some quick working code for this functionality? I am at a loss as to why this isn't working for me.
Thanks,
Ethan
rahulvyas
Nov 26, 2009, 08:27 AM
declare an instance variable in your header file when you are using interface builder like this
IBOutlet UIPickerView *AlarmSoundPicker;
in your viewDidLoad or viewWillAppear Methods put this line
[AlarmSoundPicker selectRow:Rowindex inComponent:0 animated:YES];
where Rowindex = row number of picker starts from 0 to the length you have provided.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.