一、使用方法代理
UIPickerView使用和UITableView大體相似。首先設置ViewController爲數據源,而後遵照數據源協議< UIPickerViewDataRecouce>,以後實現協議中的方法:component
一共有多少列:it
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)方法
pickerView;數據
第component列顯示多少行:協議
- (NSInteger)pickerView:(UIPickerView *)pickerViewdi
numberOfRowsInComponent:(NSInteger)component;view
上面只能設置UIPickerView有多少行、多少列,不能設置數據,若是要顯示數據,必需要設置ViewController爲UIPickerView的代理,遵照代理協議<UIPickerViewDelegate>,而後實現代理中的方法:vi
第component列的第row行顯示什麼文字:co
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component;
第component列第row行顯示怎樣的view(內容):
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:
(NSInteger)row forComponent:(NSInteger)component reusingView:
(UIView *)view;
選中了pickerView的第component列第row行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component