• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1574
  • Last Modified:

loading data from a plist file to a picker

so i have this application that has a picker that gets its data from a plist file
plisteach value in the dictionary is an array with a string and number
when a user selects a value the number should be displayed on another part of the screen. I can load a simple array from a plist but I'm finding it hard to display the different types of data. The number part of the array will be used in a calculation later, i'm just struggling even geting them to display correctly.  
//  DecayViewController.m
//  RadCalc
//  Created by kevin bett on 1/11/11.
//  Copyright 2011 Rebel Colony. All rights reserved.

#import "DecayViewController.h"

@implementation DecayViewController

@synthesize singlePicker;
@synthesize pickerData;

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
	return 1;

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
	return [pickerData count]; 

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    return self;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

	NSBundle *bundle = [NSBundle mainBundle];
	NSString *plistPath = [bundle pathForResource:@"halfLives" ofType:@"plist"];
	NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
	self.pickerData = dictionary;
	[dictionary release];


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc. that aren't in use.

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	self.pickerData = nil;
	self.singlePicker = nil;

- (void)dealloc {

	[singlePicker release];
	[pickerData release];
	[super dealloc];


Open in new window

1 Solution
I never actually see you adding the data into the picker view.

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
		return [pickerData objectAtIndex:row];

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
		NSLog(@"Selected Object: %@.", [pickerData objectAtIndex:row]);

Open in new window

Try add that and see how it goes.  Make sure you are setting the viewController to be the "DataSource" of the picker as well as the delegate.
depassionAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now