实例讲解iOS应用开发中UIPickerView滚动选择栏的用法

2020-01-14 22:13:59刘景俊
易采站长站为您分析iOS应用开发中UIPickerView滚动选择栏的用法,示例代码基于传统的Objective-C,需要的朋友可以参考下  

基础
1.UIPickerView 属性

数据源(用来告诉UIPickerView有多少列多少行)

复制代码
@property(nonatomic,assign) id dataSource;
    
代理(用来告诉UIPickerView每1列的每1行显示什么内容,监听UIPickerView的选择)
复制代码
@property(nonatomic,assign) id   delegate;
    
是否要显示选中的指示器
复制代码
@property(nonatomic)   BOOL   showsSelectionIndicator;
    
一共有多少列
复制代码
@property(nonatomic,readonly) NSInteger numberOfComponents;

 

2.UIPickerView方法

重新刷新所有列

复制代码
- (void)reloadAllComponents;

 

重新刷新第component列

复制代码
- (void)reloadComponent:(NSInteger)component;

 

主动选中第component列的第row行

复制代码
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;

 

获得第component列的当前选中的行号

复制代码
- (NSInteger)selectedRowInComponent:(NSInteger)component;

 

3.UIPickerView数据源方法

一共有多少列

复制代码
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
第component列一共有多少行
复制代码
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

 

4.UIPickerView代理方法
第component列的宽度是多少

复制代码
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
第component列的行高是多少
复制代码
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;