//
// ViewController.m
// testPickerView
//
// Created by yuyezhulan on 14/11/9.
// Copyright (c) 2014年 yuyezhulan. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
// 指定Delegate
pickerView.delegate=self;
// 显示选中框
pickerView.showsSelectionIndicator=YES;
[self.view addSubview:pickerView];
NSArray *dataArray = [[NSArray alloc]initWithObjects:@"许嵩",@"周杰伦",@"梁静茹",@"许飞",@"凤凰传奇",@"阿杜",@"方大同",@"林俊杰",@"胡夏",@"邱永传", nil];
pickerData=dataArray;
// // 添加按钮
// CGRect frame = CGRectMake(120, 250, 80, 40);
// UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// selectButton.frame=frame;
// [selectButton setTitle:@"SELECT" forState:UIControlStateNormal];
//
// [selectButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
//
// [self.view addSubview:selectButton];
}
-(void)buttonPressed:(id)sender{
NSLog(@"Button Pressed!");
}
//返回显示的列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 5;
}
//返回当前列显示的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [pickerData count];
}
#pragma mark Picker Delegate Methods
//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [pickerData objectAtIndex:row];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end