UIPickerView 用法

两个代理
UIPickerViewDelegate
UIPickerViewDataSource

// 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:
//返回component列,row行的UIView,这里只有在定制情况下才有效,其他情况返回nil

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

// Reloading whole view or single component
//重装整个UIPickerView所有列和指定列的数据
- (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

@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

@protocol UIPickerViewDelegate<NSObject>
@optional

// returns width of column and height of row for each component.

//返回指定列的宽度

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;

//返回指定列的行的高度

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;

// these methods return either a plain UIString, 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

//标准的UIPickerView内容,只有字符串
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

//自定义的UIPickerView内容,给每列每行设置一个UIView
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

这里为列component,行row返回一个UIView来显示在UIPickerView中。reusingView:(UIView *) view 是IOS内核传入的一个缓冲的UIView。在程序中可以不用吧分配UIView,就可以重用IOS传来的view
//以上方法只能二选一

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

@end

UIPickerView 用法相关推荐

  1. UIPickerView用法(左右比例,整体大小,字体大小)

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero]; pickerView.autoresizingM ...

  2. Swift - 选择框(UIPickerView)的用法

    1,选择框可以让用户以滑动的方式选择值.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...

  3. RxSwift之UI控件UIPickerView扩展的使用

    一.基本用法 ① 单列的情况 基本用法 示例代码: var pickerView : UIPickerView!// 最简单的pickerView适配器(显示普通文本) private let str ...

  4. 这个我过滤概述UIPickerView键盘处理

    一.介绍UIPickView和UIDatePicker(了解) 1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往弹出一个PickerView给他们选 ...

  5. 【iOS开发】-UIPickerView

    写在开头 昨天学习了iOS一个简单的控件. UIPickerView; UIPickerView组件类似HTML都Select组件效果,提供数据供用户选择.可以通过plist文件提供数据.UIPick ...

  6. OCUI界面设计:UIPickerView 拾取视图

    简介 UIPickerView 是一个选择器控件, 它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. UIPickerView 直接继承了 UIV ...

  7. c语言中external,static关键字用法

    static用法: 在C中,static主要定义全局静态变量.定义局部静态变量.定义静态函数. 1.定义全局静态变量:在全局变量前面加上关键字static,该全局变量变成了全局静态变量.全局静态变量有 ...

  8. Pandas_transform的用法

    先来看一个实例问题. 如下销售数据中展现了三笔订单,每笔订单买了多种商品,求每种商品销售额占该笔订单总金额的比例.例如第一条数据的最终结果为:235.83 / (235.83+232.32+107.9 ...

  9. Python中yield和yield from的用法

    yield 后面接的是 future 对象 调用方 委托生成器 yield from 直接给出循环后的结果 yield from 委托者和子生成器直接通信 yield from 直接处理stopIte ...

最新文章

  1. 举个例子,如何用GCN图卷积神经网络实现摔倒监测?
  2. Python_time模块
  3. 女性养生需知的16条健康戒律
  4. DELL服务器利用OMSA修改BIOS设置
  5. FastStone Capture
  6. 在2019年,如何成为更好的Node.js开发者?
  7. merge sort loser tree
  8. Uncaught TypeError: Cannot read property ‘getters‘ of undefined
  9. 数据结构:下列选项中,不可能是快速排序第2趟排序结果的是(2019年全国试题10)
  10. python atm银行取款系统_Python实现ATM系统
  11. 《软件需求分析(第二版)》第 3 章——需求工程的推荐方法 重点部分总结
  12. 通过这本拼图学习Bash
  13. 通过SQL语句来备份,还原数据库
  14. 穿衣助手 张凯:电商产品经理的成长之路
  15. android 底层键值映射,如何在使用android-ETE时进行键值映射.doc
  16. ROS URDF模型解析成KDL Tree
  17. 假设检验 python_假的解释|假的意思|汉典“假”字的基本解释
  18. 读懂千行百业,萤石物联云平台全新能力发布
  19. 负数在计算机中的编码形式
  20. 从苏宁电器到卡巴斯基第24篇:单证这一年(下)

热门文章

  1. 使用HTML+CSS制作一个简单的网页
  2. 我们对区块链游戏的期望太高了
  3. 使用Unity制作游戏AI
  4. 二叉树——中序遍历(递归/非递归)
  5. CY7C68013A在WIN7下64位的USB驱动程序安装过程
  6. oppo怎么广告接入_OPPO广告分模块投放的正确打开方式
  7. java流的试题_Java练习题 - Stream流
  8. uni-app实现扫描二维码功能
  9. Golang指南:顶级Golang框架、IDE和工具列表
  10. 服务器虚拟内存开机就90%,电脑开机物理内存就占了百分之90 为什么啊。