第十二篇 - UIPickerView

Posted 人生路1/5

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十二篇 - UIPickerView相关的知识,希望对你有一定的参考价值。

初始化,设置代理

UIPickerView *picker = [[UIPickerView alloc] init];
picker.dataSource = self;
picker.delegate = self;

 

  @protocol UIPickerViewDataSource, UIPickerViewDelegate;
//
//NS_CLASS_AVAILABLE_ios(2_0) __TVOS_PROHIBITED @interface UIPickerView : UIView <NSCoding, UITableViewDataSource>
//
  @property(nullable,nonatomic,weak) id<UIPickerViewDataSource> dataSource;                // default is nil. weak reference
  @property(nullable,nonatomic,weak) id<UIPickerViewDelegate>   delegate;                  // default is nil. weak reference
// ios7之后设置无效
  @property(nonatomic)        BOOL                       showsSelectionIndicator;   // default is NO
//
//// info that was fetched and cached from the data source and delegate
//获取一共多少组件(列)
  @property(nonatomic,readonly) NSInteger numberOfComponents;
//某一个组件中,一共有多少行
  - (NSInteger)numberOfRowsInComponent:(NSInteger)component;
//获取某一分区行的尺寸
  - (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;
//
//// Reloading whole view or single component
//重载所有分区
  - (void)reloadAllComponents;
//重载某一分区
  - (void)reloadComponent:(NSInteger)component;
//
//// 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
//
  @end
//
//
//__TVOS_PROHIBITED
  @protocol UIPickerViewDataSource<NSObject>
  @required
//
//// 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;
  @end
//
//__TVOS_PROHIBITED
  @protocol UIPickerViewDelegate<NSObject>
  @optional
//
//// 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
设置某一行显示的view视图
  - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view __TVOS_PROHIBITED;
//
选中某一行时执行的回调
  - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component __TVOS_PROHIBITED;
//
  @end

 

以上是关于第十二篇 - UIPickerView的主要内容,如果未能解决你的问题,请参考以下文章

第十二篇:编程范式

第十二篇 JavaScript(简称JS) 实现显示与隐藏

Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇)

开始写游戏 --- 第十二篇

R实战 第十二篇:随机数

(转)SpringBoot非官方教程 | 第十二篇:springboot集成apidoc