iOS開發之UIPickerView

一、使用方法代理

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

相關文章
相關標籤/搜索