2

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
JAL
  • 41,701
  • 23
  • 172
  • 300
Add080bbA
  • 1,818
  • 1
  • 18
  • 25
  • thankx to both iBhavin and JAL. i have realized that my dataSource was returning nil from coreData. problem solved – Add080bbA Nov 06 '14 at 12:04

2 Answers2

4

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.

iBhavin
  • 1,261
  • 15
  • 30
3

Make sure your data source array is allocated and initialized. I ran into this problem when everything was hooked up correctly (I set the data source and delegates and was conforming to the protocols), but I forgot to initialize my data source arrays before adding objects to them. My code was hitting numberOfComponentsInPickerView and numberOfRowsInComponent but not titleForRow and I couldn't figure out why. Make sure your data source is not returning nil.

Kind of a stupid edge case, but I figured I'd add my answer in case someone else runs into the same issue.

JAL
  • 41,701
  • 23
  • 172
  • 300