Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ethana

macrumors 6502a
Original poster
Jul 17, 2008
836
0
Seattle, WA
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:

Code:
- (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
 
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.
 
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.
 
You need to add an instance variable to your View Controller file to start.
 
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
 
here how it works....

declare an instance variable in your header file when you are using interface builder like this

Code:
IBOutlet UIPickerView *AlarmSoundPicker;

in your viewDidLoad or viewWillAppear Methods put this line
Code:
[AlarmSoundPicker selectRow:Rowindex inComponent:0 animated:YES];

where Rowindex = row number of picker starts from 0 to the length you have provided.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.