Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Following example for the UIPickerview controller</p> <p>.m files here</p> <pre><code>#import "SingleComponentPickerViewController.h" @implementation SingleComponentPickerViewController @synthesize singlePicker; @synthesize pickerData; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } -(IBAction)buttonPressed1 { 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 :@"Welcome" otherButtonTitles :nil]; [alert show]; [alert release]; [title release]; } - (void)viewDidLoad { NSArray *array = [[NSArray alloc] initWithObjects:@"iPhone",@"iPad",@"iPod",@"iMac",@"Mac", @"iBook",@"Safari",nil]; self.pickerData = array; [array release]; [super viewDidLoad]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)viewDidUnload { } - (void)dealloc { [singlePicker release]; [pickerData release]; [super dealloc]; } -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [pickerData count]; } -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return[pickerData objectAtIndex:row]; } @end </code></pre> <p>and .h file here</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface SingleComponentPickerViewController : UIViewController { IBOutlet UIPickerView *singlePicker; NSArray *pickerData; } @property(nonatomic , retain) UIPickerView *singlePicker; @property(nonatomic , retain) NSArray *pickerData; -(IBAction)buttonPressed1; @end </code></pre> <p>happy coding @samuel</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload