SingleComponentPickerViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:2k
源码类别:

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  SingleComponentPickerViewController.m
  3. //  Pickers
  4. //
  5. //  Created by Jeff LaMarche on 7/7/08.
  6. //  Copyright 2008 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "SingleComponentPickerViewController.h"
  9. @implementation SingleComponentPickerViewController
  10. @synthesize singlePicker;
  11. @synthesize pickerData;
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  13. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  14. // Initialization code
  15. }
  16. return self;
  17. }
  18. - (IBAction)buttonPressed:(id)sender
  19. {
  20. NSInteger row = [singlePicker selectedRowInComponent:0];
  21. NSString *selected = [pickerData objectAtIndex:row];
  22. NSString *title = [[NSString alloc] initWithFormat:@"You selected %@!", selected];
  23. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"Thank you for choosing." delegate:nil cancelButtonTitle:@"You're Welcome" otherButtonTitles:nil];
  24. [alert show];
  25. [alert release];
  26. [title release];
  27. }
  28. - (void)viewDidLoad {
  29. NSArray *array = [[NSArray alloc] initWithObjects:@"Luke", @"Leia", @"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando", nil];
  30. self.pickerData = array;
  31. [array release];
  32.  
  33. }
  34. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  35. // Return YES for supported orientations
  36. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  37. }
  38. - (void)didReceiveMemoryWarning {
  39. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  40. // Release anything that's not essential, such as cached data
  41. }
  42. - (void)dealloc {
  43. [singlePicker release];
  44. [pickerData release];
  45. [super dealloc];
  46. }
  47. #pragma mark -
  48. #pragma mark Picker Data Source Methods
  49. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  50. {
  51. return 1;
  52. }
  53. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  54. {
  55. return [pickerData count];
  56. }
  57. #pragma mark Picker Delegate Methods
  58. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  59. {
  60. return [pickerData objectAtIndex:row];
  61. }
  62. @end