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

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  DoubleComponentPickerViewController.m
  3. //  Pickers
  4. //
  5. //  Created by Jeff LaMarche on 7/7/08.
  6. //  Copyright 2008 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "DoubleComponentPickerViewController.h"
  9.  
  10. @implementation DoubleComponentPickerViewController
  11. @synthesize doublePicker;
  12. @synthesize breadTypes;
  13. @synthesize fillingTypes;
  14. -(IBAction)buttonPressed:(id)sender
  15. {
  16. NSInteger breadRow = [doublePicker selectedRowInComponent:kBreadComponent];
  17. NSInteger fillingRow = [doublePicker selectedRowInComponent:kFillingComponent];
  18. NSString *bread = [self.breadTypes objectAtIndex:breadRow];
  19. NSString *filling = [self.fillingTypes objectAtIndex:fillingRow];
  20. NSString *message = [[NSString alloc] initWithFormat:@"Your %@ on %@ bread will be right up.", filling, bread];
  21. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you for your order" message:message delegate:nil cancelButtonTitle:@"Great!" otherButtonTitles:nil];
  22. [alert show];
  23. [alert release];
  24. [message release];
  25. }
  26. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  27. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  28. // Initialization code
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. NSArray *breadArray = [[NSArray alloc] initWithObjects:@"White", @"Whole Wheat", @"Rye", @"Sourdough", @"Seven Grain", nil];
  34. self.breadTypes = breadArray;
  35. [breadArray release];
  36. NSArray *fillingArray = [[NSArray alloc] initWithObjects:@"Ham", @"Turkey", @"Peanut Butter", @"Tuna Salad", @"Chicken Salad", @"Roast Beef", @"Vegemite", nil];
  37. self.fillingTypes = fillingArray;
  38. [fillingArray release];
  39. }
  40. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  41. // Return YES for supported orientations
  42. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  43. }
  44. - (void)didReceiveMemoryWarning {
  45. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  46. // Release anything that's not essential, such as cached data
  47. }
  48. - (void)dealloc {
  49. [doublePicker release];
  50. [breadTypes release];
  51. [fillingTypes release];
  52. [super dealloc];
  53. }
  54. #pragma mark -
  55. #pragma mark Picker Data Source Methods
  56. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  57. {
  58. return 2;
  59. }
  60. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  61. {
  62. if (component == kBreadComponent)
  63. return [self.breadTypes count];
  64. return [self.fillingTypes count];
  65. }
  66. #pragma mark Picker Delegate Methods
  67. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  68. {
  69. if (component == kBreadComponent)
  70. return [self.breadTypes objectAtIndex:row];
  71. return [self.fillingTypes objectAtIndex:row];
  72. }
  73. @end