cocoa touch——UIPickerView
2016-07-04 17:34
477 查看
概述
UIPickerView,选择器控件,可以实现单列或多列选择UIPickerView
appearance
@property(nonatomic) BOOL showsSelectionIndicator; // default is NO
注意:
ios7之前,此属性控制selection indicator显示,默认值为NO,ios7及以后,此属性不再起作用,无论设置YES或NO,selection indicator总显示
selection
// selection. in this case, it means showing the appropriate row in the middle - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; // scrolls the specified row to center. - (NSInteger)selectedRowInComponent:(NSInteger)component; // returns selected row. -1 if nothing selected
dataSource
@property(nullable,nonatomic,weak) id<UIPickerViewDataSource> dataSource; // default is nil. weak reference
component&row
view
// info that was fetched and cached from the data source @property(nonatomic,readonly) NSInteger numberOfComponents; - (NSInteger)numberOfRowsInComponent:(NSInteger)component;
dataSource
// returns the number of 'columns' to display. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; // returns the # of rows in each component.. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
注意:
view获取的是cache值
dataSource定制view的component和row
delegate
@property(nullable,nonatomic,weak) id<UIPickerViewDelegate> delegate; // default is nil. weak reference
cell appearance
view
// info that was fetched and cached from the delegate - (CGSize)rowSizeForComponent:(NSInteger)component; // returns the view provided by the delegate via pickerView:viewForRow:forComponent:reusingView: // or nil if the row/component is not visible or the delegate does not implement // pickerView:viewForRow:forComponent:reusingView: - (nullable UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
delegate
// returns width of column and height of row for each component. - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component __TVOS_PROHIBITED; - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component __TVOS_PROHIBITED; // these methods return either a plain NSString, a NSAttributedString, or a view (e.g UILabel) to display the row for the component. // for the view versions, we cache any hidden and thus unused views and pass them back for reuse. // If you return back a different object, the old one will be released. the view will be centered in the row rect - (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component __TVOS_PROHIBITED; - (nullable NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED; // attributed title is favored if both methods are implemented - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view __TVOS_PROHIBITED;
注意:
view获取的只是cache值
delegate定制view的cell appearance
delegate提供了三个版本的cell appearance:NSString,NSAttributedString,UIView,分别表示UILabel(plain),UILabel(attributed),UIView,优先级:UIView>NSAttributedString>NSString
cell select
delegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component __TVOS_PROHIBITED;
reload
// Reloading whole view or single component - (void)reloadAllComponents; - (void)reloadComponent:(NSInteger)component;
注意:
view绘制前会调用一次reloadAllComponents,component从默认值0改变为自定义值
reloadAllComponents会调用dataSource的定制component和row方法,delegate的定制cell appearance的其中一个版本,如果component值发生改变,会调用delegate的定制cell size方法,如果component值没有改变,不会调用delegate的定制cell size方法
reloadComponent会调用dataSource的指定component的定制row方法,delegate的指定component的定制cell appearance的其中一个版本
相关文章推荐
- C#使用委托(delegate)实现在两个form之间传递数据的方法
- C#利用delegate实现Javascript的each方法
- Query中click(),bind(),live(),delegate()的区别
- 详解jquery事件delegate()的使用方法
- jQuery中 delegate使用的问题
- 浅谈jquery中delegate()与live()
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- EasyUI中datagrid在ie下reload失败解决方案
- jQuery中delegate与on的用法与区别示例介绍
- JS delegate与live浅析
- jQuery事件 delegate()使用方法介绍
- .NET笔记之:Delegate内部原理的分析
- jQuery中bind(),live(),delegate(),on()绑定事件方法实例详解
- C#匿名方法与Delegate类型转换错误分析
- C#数据绑定控件中的DataSource属性浅谈
- 解决微信浏览器Javascript无法使用window.location.reload()刷新页面
- jQuery中delegate和on的用法与区别详细解析
- 实例讲解iOS应用开发中UIPickerView滚动选择栏的用法
- iOS App中UIPickerView选择栏控件的使用实例解析
- 详解iOS App中UIPickerView滚动选择栏的添加方法