UIPickerView wont display data properly - iphone

I am trying to make a UIPickerView with data #"0", #"1", #"2", #"3"... display on rows,
it will be a 2 columns pickerView.
here is my code:
this is .h file
#import <UIKit/UIKit.h>
#interface CustomNumberViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
#property (strong, nonatomic) IBOutlet UIPickerView *numberPicker;
#property(strong, nonatomic)NSArray *listOfNumbers;
#property (strong,nonatomic)NSString *numberOfFirstColumn;
#property(strong,nonatomic)NSString *numberOfSecondColumn;
#end
this is .m file
#import "CustomNumberViewController.h"
#interface CustomNumberViewController ()
#end
#implementation CustomNumberViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
//UIView background
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:#"pickerbackground.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
//init picker
self.numberPicker.showsSelectionIndicator = TRUE;
self.listOfNumbers = [[NSArray alloc] initWithObjects:#"0",#"1",#"2",#"3",nil];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//Number of rows to display in each component
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component==0) {
return [self.listOfNumbers count];
}
return [self.listOfNumbers count];
}
//Number of columns to display
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
//define what to display in each rows and columns
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component==0) {
return [self.listOfNumbers objectAtIndex:row];
}
return [self.listOfNumbers objectAtIndex:row];
}
//selected number to be stored in nsstring
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component==0) {
self.numberOfFirstColumn = [self.listOfNumbers objectAtIndex:row];
}
self.numberOfSecondColumn = [self.listOfNumbers objectAtIndex:row];
}
#end
My problem is if I try to run the app, the UIPickerView isn't filled with any data... so absolutely empty....
and if i try to scull the 'selected indicator', app will crash at once...
this is the error msg ->
Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableViewRowData.m:1630
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path ( 2 indexes [0, 0])'
any suggestions ? thanks

It looks like you are not creating your UIPickerView in code. Did you make sure that the delegate and data source of the picker is the class you are trying to create it in? If it is not, it will not know what you want to have in it.

Related

iOs5, Trying to understand the UIPickerView and how to connect it to my custom class

Ok I am trying to connect a UIPickerView with a custom class. The idea is to have 3 picker views in one normal view.
So far I have created one view and bound it to my class TestView.h
Then I added a picker view to the view in the storyboard (iOS 5)
I then created a class for this picker view:
#interface TestPickerView : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource>
{
NSArray *data;
}
Then tried to add a Property to my normal view (TestView.h)
#import "TestPickerView.h"
#interface TestView : UIViewController
#property (strong, nonatomic) IBOutlet TestPickerView *myTestPicker;
#end
But how do i bind the UIPickerView inside my normal view to this class/property?
I will in the end have 3 UIPickerView's and my idea was to have 3 references in my UIViewController to control these UIPickerViews. That way I could set the data (datasource) using the properties once when the normal view is loading and then the PickerViews would just show. Hopefully i would also be able to get notified in my normal view when the value in one of the views occur.
Please call your TestView >> TestViewController instead, as it is a controller.
In your storyboard, select the PickerView and change it's class name to TestPickerView.
After that just create your three IBOutlets and connect the PickerViews. That's it.
// edit: To explain, how you distinguish between the pickers. Make 3 outlets, e.g.:
IBOutlet TestPickerView *picker1;
IBOutlet TestPickerView *picker2;
IBOutlet TestPickerView *picker3;
And than in your delegate method, check which picker did call the delegate, e.g.:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView == self.picker1)
{
// picker1
}
else if(pickerView == self.picker2)
{
// picker2
}
else
{
// picker3
}
}
Here you go dude, this is how I did it on several of my apps and games.
#import <UIKit/UIKit.h>
#pragma mark - Delegate Protocol
#protocol someDelegate
#required
-(void)somePickerFinishedPicking:(id)item;
#end
#pragma mark - Class interface
#interface SomePicker : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
{
NSMutableArray* dataSource;
}
#pragma mark - Property Istantiation
#property (nonatomic, retain) NSMutableArray* dataSource;
#property (nonatomic, retain) id <someDelegate> pickDelegate;
#pragma mark - Constructors / Destructors
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
- (void) didReceiveMemoryWarning;
- (void) dealloc;
- (void) createDataSource;
#pragma mark - View Lifecycle
- (void) viewDidLoad;
#pragma mark - UIPicker Protocols
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
-(UIView*) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
#pragma mark - Delegate Protocols
-(void) handlePickerDidFinish:(id)item;
#end
this for your .m
#pragma mark - Class Implementation
#implementation SomePicker
#pragma mark - Variable synthesize
// ARRAYS
#synthesize dataSource;
// DELEGATES
#synthesize pickDelegate = _pickDelegate;
#pragma mark - Constructors / Deconstructors
// Class initialization
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
dataSource = [[NSMutableArray alloc] init];
[self createDataSource];
}
return self;
}
// Handles memory warning events
- (void)didReceiveMemoryWarning
{
// Release the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
// Garbage Collection
- (void) dealloc;
{
// Release what you need
self.dataSource = nil;
[super dealloc];
}
// Creates the occasion entries for the picker
-(void)createDataSource
{
NSMutableDictionary* dataDictionary = [[NSMutableDictionary alloc] init];
// create your data source here or just forget about this and pass it from the parentViewController.
[dataDictionary release];
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad;
{
[super viewDidLoad];
UIPickerView* occasionsPicker = [[UIPickerView alloc] init];
[occasionsPicker setDataSource:self];
[occasionsPicker setDelegate:self];
[occasionsPicker setTag:888];
[occasionsPicker selectRow:500 inComponent:0 animated:YES];
[self.view addSubview:occasionsPicker];
[occasionsPicker release];
[self handlePickerDidFinish:[[self.dataSource objectAtIndex:(500 % self.dataSource.count)] objectForKey:#"key"]];
}
#pragma mark - UIPicker Protocols
// Creates the rows in the picker.
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
// Endless roll illusion else just bind it to the size of the data source
return 1000;
}
// Determines the number of columns in the picker
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
// Add however many columns you need
return 1;
}
// Handles the event when the user picks a row.
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
//this does something with the row selected
[self handlePickerDidFinish:[[self.dataSource objectAtIndex:(row % self.dataSource.count)] objectForKey:#"key"]];
}
// Creates the custom view for each cell so the text shows in accordance to the App Style
-(UIView*) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* customRowLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)] autorelease];
customRowLabel.font = [UIFont fontWithName:#"HelveticaNeue" size: 16];
customRowLabel.textColor = [UIColor colorWithRed:kColorRed green:kColorGreen blue:kColorBlue alpha:1];
customRowLabel.textAlignment = UITextAlignmentCenter;
customRowLabel.backgroundColor = [UIColor clearColor];
customRowLabel.text = [[self.dataSource objectAtIndex:(row % self.dataSource.count)] objectForKey:#"key"];
return customRowLabel;
}
#pragma mark - Delegate Protocols
// Notifies Delegate class that an action has been perfomed and passes the Mood String selected
-(void)handlePickerDidFinish:(id)item
{
[self.pickDelegate somePickerFinishedPicking:item];
}
#end
And just instantiate it like so on your parent ViewController:
CGRect rectPicker = CGRectMake(60, 100, 200, 216);
self.somePicker = [[[SomePicker alloc] init] autorelease];
[self.somePicker setPickDelegate:self];
[self.somePicker.view setBackgroundColor:[UIColor clearColor]];
self.somePicker.view.frame = rectPicker;
[self.somePicker.view setTag:777];
[self.somePicker.view setAlpha:0];
[self.view addSubview:self.somePicker.view];
~/End of Line

Ui Picker view error cant resolve

Still trying to figure out the UI picker view, 2 days on it now and for some reason im just stuck on this. Any advice please on what im doing wrong. Ive got a yellow triangle saying "Incomplete implementation" and a red triangle saying "Use of undeclared identifier numberOfComponentsinPickerView"
.h
#import <UIKit/UIKit.h>
#interface pick3 : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
UIPickerView *select;
NSArray *list;
}
#property (strong, nonatomic) IBOutlet UIPickerView *select;
#end
.m
#import "pick3.h"
#interface pick3 ()
#end
#implementation pick3
#synthesize select;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
{
list = [[NSArray alloc] initWithObjects:#"Employed", #"Student", #"Retired", #"Homemaker", #"Self-employed", #"Unemployed", #"Other", nil];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//One column
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//set number of rows
return list.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//set item per row
return [list objectAtIndex:row];
}
}
It's just a typo on your viewDidLoad: method.
You have an extra '{' before your 'list' and and extra '}' at the end of the file. Just remove them and you'll be ok.
Try this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
list = [[NSArray alloc] initWithObjects:#"Employed", #"Student", #"Retired", #"Homemaker", #"Self-employed", #"Unemployed", #"Other", nil];
}

Two uipicker in the same view

what i am trying to do is to put two uipickers on the same view, i read somewhere that one of them should have its own separate delegate i tried to do so but i couldn't make it work properly.
Some times when i run the application the second application just stops working with no errors on the console.
this is the .h file for the view:
#interface FirstViewController : UIViewController {
IBOutlet UIPickerView *cities;
NSMutableArray *array;
NSString *picked;
}
#property(nonatomic,retain) IBOutlet UIPickerView *cities;
#property(nonatomic,retain) IBOutlet NSMutableArray *array;
and here is the .m:
#implementation FirstViewController
#synthesize cities,array;
-(void) getCities:(NSString *)link{
url=link;
NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
if([str length]==0){
[str release];
return;
}
SBJsonParser *parser=[[SBJsonParser alloc] init];
array=[[parser objectWithString:str] copy];
[receivedData release];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView
return 1; // We only need one column so we will return 1.
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have.
return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array.
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
picked=[array objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
return [array objectAtIndex:row]; // We will set a new row for every string used in the array.
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[sv setScrollEnabled:TRUE];
[sv setContentSize:CGSizeMake(320, 800)];
[self getCities:#"any url"];
[super viewDidLoad];
}
- (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;
}
- (void)dealloc
{
[super dealloc];
}
#end
and for the second uipicker i added an nsobject to the view and changed its class to "SecondPickerDelegate" which i created before and this is its code:
.h
#import <UIKit/UIKit.h>
#interface FirstViewSecondPickerDelegate : UIViewController<UIPickerViewDelegate>{
IBOutlet UIPickerView *specialities;
NSMutableArray *array;
NSString *picked;
}
#property(nonatomic,retain) IBOutlet UIPickerView *specialities;
#property(nonatomic,retain) NSMutableArray *array;
#property(nonatomic,retain) NSString *picker;
#end
the .m file:
#import "FirstViewSecondPickerDelegate.h"
#import "JSON.h"
#implementation FirstViewSecondPickerDelegate
#synthesize specialities,array,picker;
-(void) getSpecialities:(NSString *)link{
url=link;
NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
if([str length]==0){
[str release];
return;
}
SBJsonParser *parser=[[SBJsonParser alloc] init];
array=[[parser objectWithString:str] copy];
for(int i=0;i<[array count];i++){
NSLog(#"index %i",i);
NSLog(#"value %#",[array objectAtIndex:i]);
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView
return 1; // We only need one column so we will return 1.
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have.
return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array.
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
picked=[array objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
return [array objectAtIndex:row]; // We will set a new row for every string used in the array.
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
picked=#"1";
[self getSpecialities:#"http://localhost:8080/Test/gs"];
}
return self;
}
/*
-(void) viewDidLoad{
[super viewDidLoad];
}
*/
- (void)dealloc
{
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
If any one has a working example for such case please help.
You don't need separate delegates for two UIPickerView's in the same view.
Use the UIPickerView tag property, and then you can differentiate between them in delegate methods.

UIPickerView crashes app when scrolling past beginning or end of list

I'm new to iOS dev, so this is probably easy to fix. I have a custom view controller in which I'm adopting the protocols to control a UIPickerView in a nib. Everything works fine unless, in the iPad simulator, I scroll the picker beyond the first item in the list or the last item in the list and release. It kicks the following error:
Thread 1: Program received signal: "EXC_BAD_ACCESS"
on this line of my main.m class:
int retVal = UIApplicationMain(argc, argv, nil, nil);
Relevant code follows:
ViewController.h
#interface BirdColorViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
IBOutlet UIPickerView *birdColorPicker;
NSArray *birdColors;
}
#property (nonatomic,retain) IBOutlet UIPickerView *birdColorPicker;
Viewcontroller.m
- (void)dealloc
{
[birdColorPicker release];
[super dealloc];
}
...
- (void)viewDidLoad
{
[super viewDidLoad];
birdColors = [NSArray arrayWithObjects:#"Blue",#"Yellow",#"Red",nil];
birdColorPicker.delegate = self;
birdColorPicker.dataSource = self;
}
...
#pragma mark - UIPickerViewDataSource methods
//(UIPickerView *)thePickerView
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [birdColors count];
}
#pragma mark - UIPickerViewDelegate methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [birdColors objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Set value in prefs/model
}
Try:
birdColors = [[NSArray alloc] initWithObjects:#"Blue",#"Yellow",#"Red",nil];
instead of birdColors = [NSArray arrayWithObjects:#"Blue",#"Yellow",#"Red",nil];
Make birdColors a property also (nonatomic, retain) like you do with the pickerView.
Your array is not being retained, so you're accessing zombie memory.
Set NSZombieEnabled=YES in the properties/General panel of your Executable. That will tell you exactly what is being accessed.

Two pickers in a view -iphone app

I am using two UIPickers in a view.
first picker has 3 components and second has one.
but when I select items, it shows correct items from first picker but always return first item from second picker regardless of selected row.
Please help.
here is the code I am using.
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
if (pickerView == triplePicker)
return 3;
else {
return 1;
}
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (pickerView == triplePicker) {
if (component == kColorComponent)
return[colorList count];
if (component == kClarityComponent)
return[clarityList count];
return[shapeList count];
}
else{
return [listPickerItems count];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (pickerView == triplePicker) {
if (component == kColorComponent)
return [colorList objectAtIndex:row];
if (component == kClarityComponent)
return [clarityList objectAtIndex:row];
return [shapeList objectAtIndex:row];
}
else{
return [listPickerItems objectAtIndex:row];
}
}
in buttonpressed event I have following for second picker to return the item selected:
NSInteger pickrow = [listPicker selectedRowInComponent:0];
NSString *picked = [listPickerItems objectAtIndex:pickrow];
I would definitely suggest using two separate delegates to handle two pickers.
Aside from that, I'm going to guess that you're using Interface Builder to set up your view. If that's the case check if you have properly linked your listPicker with your File's Owner. If listPicker would be nil, then selectedRowInComponent: would always return null (0 for NSInteger), hence would always select the first item in your array.
EDIT: Some sample code for separate delegates:
You need to create a second class to be your delegate, like this:
FirstPickerDelegate.h
#import <Foundation/Foundation.h>
#class UntitledViewController;
#interface FirstPickerViewDelegate : NSObject <UIPickerViewDelegate, UIPickerViewDataSource> {
NSArray* values;
IBOutlet UntitledViewController* viewController;
}
-(void) loadData;
#property (nonatomic, retain) NSArray* values;
#property (nonatomic, assign) IBOutlet UntitledViewController* viewController;
#end
FirstPickerViewDelegate.m
#import "FirstPickerViewDelegate.h"
#implementation FirstPickerViewDelegate
#synthesize values;
#synthesize viewController;
-(id) init
{
if ( self = [super init] )
{
[self loadData];
}
return self;
}
-(void) loadData
{
NSArray* array = [[NSArray alloc] initWithObjects:#"first", #"second", #"third", nil];
self.values = array;
[array release];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [values count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [values objectAtIndex:row];
}
-(void) dealloc
{
self.values = nil;
[super dealloc];
}
#end
Your ViewController (UntitledViewController here, sorry about the name):
#import <UIKit/UIKit.h>
#class FirstPickerViewDelegate;
#interface UntitledViewController : UIViewController {
IBOutlet UIPickerView* firstPicker;
IBOutlet FirstPickerViewDelegate* firstDelegate;
}
#property (nonatomic, retain) IBOutlet UIPickerView* firstPicker;
#property (nonatomic, retain) IBOutlet FirstPickerViewDelegate* firstDelegate;
#end
Basically you need to drop an NSObject on your object list, and change it's class to FirstPickerViewDelegate, then make connections like this:
I feel I overelaborated this time, but I'm in a good mood today so whatever :P
About the main question: double check that listPicker is not nil at the time of pressing the button, if it is not, try to use
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
to track down the error.