UIPickerView only shows question marks

Discussion in 'iOS Programming' started by jimerman, Mar 27, 2011.

  1. jimerman macrumors newbie

    Feb 10, 2010
    Thanks for helping a newb out!! This is not making sense to me. I did find another thread in this forum with another guy who had a typo in his delegate method, but I don't have that typo and it still shows up as questionmarks. What am I missing?

    First, I have a view controller that is the data source for the picker. In the view controller implementation, I have the following:

    1. I have an NSArray* property "categories" - the initWithNibName method initializes these. The initialization looks something like this:

    categories = [[NSArray alloc] initWithObjects:@"Indoors", @"Outdoors", nil];
    2. I have the UIPickerViewDelegate and UIPickerViewDataSource protocols adopted.

    3. I have the following methods:

    #pragma mark -
    #pragma mark UIPickerViewDataSource
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
        return [categories count];
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
        return 1;
    #pragma mark -
    #pragma mark UIPickerViewDelegate
    // Retrieve the value for the row to display
    - (NSString *)pickerView:(UIPickerView *)pickerView 
        return [categories objectAtIndex:row];
    When I run and set a breakpoint in the pickerView:titleForRow:forComponent, it doesn't break.
  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    That indicates the your pickerView hasn't had the delegate set.

    Assuming you have the picker in an Interface Builder file, control drag from it to Files Owner and attach to both the delegate and the datasource. Also remember that Files Owner needs its Type set to your customer view controller, or what ever Class is handling your actions and outlets.

Share This Page