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

相关文章
相关标签/搜索