初始化
UIPickerView *flagPicker = [[UIPickerView alloc] init];
// 設(shè)置代理和數(shù)據(jù)源
flagPicker.dataSource = self;
flagPicker.delegate = self;
代理方法
// 每列寬度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
}
// 返回選中的行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
// 顯示每行每列的數(shù)據(jù)
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
}
數(shù)據(jù)源方法
// 幾列數(shù)據(jù)
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
}
// 每列的行數(shù)
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
}
需求:點(diǎn)擊按鈕彈出鍵盤(pán)UIPickerView

將textFiled的鍵盤(pán)設(shè)置為pickerView;
然后將textFiled變?yōu)榈谝豁憫?yīng)者,這是彈出的鍵盤(pán)就是自定義的UIPickerView鍵盤(pán);
- (IBAction)onclick:(id)sender {
self.textFiled.inputView = self.pickerView;
[self.textFiled becomeFirstResponder];
}