Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Loading Data into UIPickerView?

mckenziedavemckenziedave LondonPosts: 2New Users Noob
So I'm trying to build an app which works alongside a database of PDF's. What I need is for the app to look at all of the files (PDF's) which are stored and to pull the certain files out, check this against the database and then show a list of which PDF's are available on a UIPicker.

My first step would be that the app checks the files and creates a picker wheel which has been populated with the countries for which there is data in the directory.

To make this work I have created a standard format for the file names: 'Country-Airfield-Plate Name-Date.pdf', e.g. “UK-London Heathrow-ILS DME NDB 27-100214.pdf”. I've split this filename first at the full stop to get two strings: 'UK-London Heathrow-ILS DME NDB 27’ and ‘pdf’, and then we split the title at the hyphens to get ‘UK’, ‘London Heathrow’ and ‘ILS DME NDB 27’.

The app will check the first string for the country information, then the second for the airfield and will then display a list of the third strings for the appropriate airfield.

How can I First Fetch the data from database for a particular field for eg. country make a NSArray form that data and load that NSArray to UIPickerView, then use that array in UIPickerView Delegate and Datasource methods?


  • ZuningoZuningo Posts: 66Registered Users @

    depending which db you use the source code has to be written (core data, sqlite, etc.) to fetch the records and build an array.

    then in your viewcontroller:
    // inside header (viewcontroller.h)
    @interface UmrechnenViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
    // inside implementation (viewcontroller.m)
    - (void)viewDidLoad {
        [super viewDidLoad];
        _pickerData = [NSArray arrayWithObjects:@"book1", @"book2", @"book3", nil];
        UIPickerView *picker1 = [[UIPickerView alloc] init];
        picker1.delegate = self;
        picker1.dataSource = self;
        picker1.showsSelectionIndicator = YES;
    -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row   forComponent:(NSInteger)component {
        return [_pickerData objectAtIndex:row];
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component {
        return [_pickerData count];
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
        return 1;

Sign In or Register to comment.