UIPickerView not displaying

4thSpace picture 4thSpace · May 2, 2010 · Viewed 7.8k times · Source

I have a UIPickerView on a UIView. I've implemented its protocol in the .h and delegates in the .m files:

 <UIPickerViewDataSource, UIPickerViewDelegate>

In IB, I've connected the above to the picker, which I also have an IBoutlet for. The methods look like this:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [self.arr count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row  forComponent:(NSInteger)component {
return @"test";
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//do something
}

Any ideas which piece I'm missing to get the picker working?

Answer

user121301 picture user121301 · May 2, 2010

If the delegate methods are not getting called, then in IB double check that the picker view's delegate and datasource outlets are connected to File's Owner.

In the .h file, the picker view outlet should be declared like this:

@property (nonatomic, retain) IBOutlet UIPickerView *pickerView;