iPhone控件之UIPickerView

1 #import <UIKit/UIKit.h>
2
3 @interface UITestViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
4 {
5
6 }
7
8 @end
 1 //
2 // UITestViewController.m
3 // UITest
4 //
5
6 #import "UITestViewController.h"
7
8 @implementation UITestViewController
9
10 - (void)viewDidLoad {
11
12 [super viewDidLoad];
13
14 CGRect pickerFrame = CGRectMake(0,120,0,0);
15
16 UIPickerView *myPicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
17 myPicker.dataSource = self;
18 myPicker.delegate = self;
19 myPicker.showsSelectionIndicator = YES;
20
21 [self.view addSubview:myPicker];
22
23 [myPicker release];
24 }
25
26 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
27
28 return 1;
29 }
30
31 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
32
33 return 10;
34 }
35
36 - (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
37
38 return [NSString stringWithFormat:@"Row %i",row];
39 }
40
41 - (void)didReceiveMemoryWarning {
42 // Releases the view if it doesn't have a superview.
43 [super didReceiveMemoryWarning];
44
45 // Release any cached data, images, etc that aren't in use.
46 }
47
48 - (void)viewDidUnload {
49 // Release any retained subviews of the main view.
50 // e.g. self.myOutlet = nil;
51 }
52
53
54 - (void)dealloc {
55 [super dealloc];
56 }
57
58 @end



posted @ 2012-03-13 13:06  FoxBabe  阅读(270)  评论(0编辑  收藏  举报