Search code examples
iosobjective-cuipickerviewuipickerviewdatasourceuipickerviewdelegate

UIPickerView pickerView:titleForRow:rowforComponent method not called


I have a UIPickerView in my storyboard. The UIViewController containing it has interface declarations set

@interface ContactDetail : UIViewController <ABPeoplePickerNavigationControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate,UIAlertViewDelegate, UITextFieldDelegate>

on view Load, pickerview delegation set

pickerView_RelationshipType.dataSource=self;
pickerView_RelationshipType.delegate = self;
pickerView_RelationshipType.showsSelectionIndicator = YES;

all UIPickerView datasource and delegate methods are triggered except those 2

pickerView:titleForRow:rowforComponent
and
pickerView:viewForRow:forComponent:reusingView

those following are called, no problem

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
    - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component

Solution

  • what's in numberOfComponentsInPickerView ?

    If your numberOfRows returning 0, then your delegate method will never be called - the picker won't ask for the title of a row if it doesn't think it has any rows to display.