iosobjective-cuipickerviewuipickerviewdatasource

CPPickerView DataSource


Using CPPickerView. I have it working and have currently been coding for a bit too long i think and my brain has gone dead so any help would be appreciated. I know the answer is simple but for the life of me i just can't see it.

I want to load an array of strings into the view, not numbers.

The current method to use for numbers is:

- (NSString *)pickerView:(CPPickerView *)pickerView titleForItem:(NSInteger)item
{
return [NSString stringWithFormat:@"%i", item + 1];
}

How do i create/edit a method to make strings appear instead of integers?


Solution

  • If the strings are in an array then perhaps this is what you want:

    - (NSString *)pickerView:(CPPickerView *)pickerView titleForItem:(NSInteger)item {
        return yourStringArray[item];
    }