http://www.buildapp.net/iphone/show.asp?id=54891

  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. #import "cocos2d.h"
  4.  
  5. @interface AppDelegate {
  6.     UIWindow *window;
  7.     NSArray *pickerValues;
  8. }
  9. @property (nonatomic, retain) UIWindow window;
  10. @property (nonatomic, retain) NSArray *pickerValues;
  11. @end
  12.  
  13.  
  14. @implementation AppDelegate
  15. @synthesize window, pickerValues;
  16.  
  17. -(void)applicationDidFinishLaunching:(UIApplication *)application {
  18.  
  19.     // Create Window
  20.     window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  21.     [window setUserInteractionEnabled:YES];
  22.     [window setMultipleTouchEnabled:YES];
  23.  
  24.     // Set up Director and attach to window
  25.     [[Director sharedDirector] attachInWindow:window];
  26.     [[Director sharedDirector] setLandscape:YES];
  27.     [[Director sharedDirector] runWithScene:[MyScene node]];
  28.  
  29.     // Create one large view and rotate the coordinates to landscape
  30.     UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,480.0f, 320.0f)];
  31.     parentView.transform = CGAffineTransformIdentity;
  32.     parentView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
  33.     parentView.bounds = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
  34.  
  35.     // Initialize picker and its data source
  36.     pickerValues = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",nil];
  37.     UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 195.0f, 320.0f, 125.0f)];
  38.     [pickerView setDelegate:self];
  39.  
  40.     // Attach picker to parent view and parent view to window
  41.     [parentView addSubview:pickerView];
  42.     [window addSubview:parentView];     
  43.     [window makeKeyAndVisible];
  44. }
  45.  
  46. - (void) dealloc {
  47.     [window release];
  48.     [pickerValues release];
  49.     [super dealloc];
  50. }
  51.  
  52. // ====================
  53. // UIPicker Callbacks
  54. // ====================
  55.  
  56. // Fire when new picker values are selected
  57. - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  58.     NSString *numberSequence = [NSString stringWithFormat:@"Sequence: %@%@%@",
  59.                                                         [pickerValues objectAtIndex:[thePickerView selectedRowInComponent:0]],
  60.                                                         [pickerValues objectAtIndex:[thePickerView selectedRowInComponent:1]],
  61.                                                         [pickerValues objectAtIndex:[thePickerView selectedRowInComponent:2]]];
  62.  
  63.     NSLog(numberSequence);
  64. }
  65.  
  66.  
  67. // Number of picker wheels in the picker
  68. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView                                                  {
  69.     return 3;
  70. }
  71.  
  72. // Number of items in each picker wheel
  73. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  74.     return [pickerValues count];
  75. }
  76.  
  77.  
  78. // Title for Row #
  79. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  80.     return [pickerValues objectAtIndex:row];
  81. }
  82.  
  83.  
  84. // Row height in pixels
  85. - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
  86.     return 40.0;
  87. }
  88.  
  89. // Column width in pixels
  90. - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
  91.     return 90.0f;
  92. }
  93. // ====================
  94.  
  95. @end