This class covers the basics of Spinners in iPhone App development.

Spinners

Project

Pickers

Views

	DatePickerViewController
	SingleComponentPickerViewController
	DoubleComponentPickerViewController
	DependentComponentPickerViewController
	CustomPickerViewController

Code for

PickersAppDelegate.h

UITabBarController * rootController;
@property (nonatomic, retain) IBOutlet UITabBarController * rootController;

PickersAppDelegate.m

@synthesize rootController;
[window addSubview:rootController.view];
[rootController release];

SingleComponentPickerViewController.h

@interface SingleComponentPickerViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
	IBOutlet	UIPickerView *singlePicker;
				NSArray	*pickerData;
}
@property (nonatomic, retain) UIPickerView *singlePicker;
@property (nonatomic, retain) NSArray *pickerData;
- (IBAction)buttonPressed:(id)sender;
@end

SingleComponentPickerViewController.m

- (IBAction)buttonPressed:(id)sender
{
	NSInteger row = [singlePicker selectedRowInComponent:0];
	NSString *selected = [pickerData objectAtIndex:row];
	NSString *title = [[NSString alloc] initWithFormat:@"You selected %@!", selected];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"Thank you for choosing." delegate:nil cancelButtonTitle:@"You're Welcome" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[title release];
}
- (void)viewDidLoad {
	NSArray *array = [[NSArray alloc] initWithObjects:@"Luke", @"Leia", @"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando", nil];
	self.pickerData = array;
	[array release];
	 
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	return [pickerData count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	return [pickerData objectAtIndex:row];
}

Resources For Gambling

Lemons.zip