选择器的使用——郭挺
来源:互联网 发布:淘宝团扇 编辑:程序博客网 时间:2024/06/07 09:43
UIPickerView和UIDataPicker都是选择器,它们的外貌也非常相似,但它们却继承自不同的父类。
1.UIPickerView继承自UIView
2.UIDataPicker继承自UIcontrol,而UIcontrol也继承自UIView
UIPickerView直接继承了UIView,没有继承UIControl,因此,它不能像UIControl那样绑定事件处理方法,UIPickerView的事件处理由其委托对象完成。
下面是uipickerview的一些属性和创建shiyong
//宽和高是固定的UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480-216, 0, 0)];//设置数据源和委托pickerView.dataSource = self;pickerView.delegate = self;//是否显示指示器pickerView.showsSelectionIndicator = YES; //默认为yes[self.view addSubview:pickerView];
数据源方法,必须实现
// returns the number of ‘columns’ to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0) {
return 5;//[_data count];
}
//返回第一列选择的行的索引
}
代理方法
//返回每个component中row的title
- (nullable NSString )pickerView:(UIPickerView )pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
}
//返回每个component中row的View
- (UIView )pickerView:(UIPickerView )pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view
{ }
}
//选择某一行调用该方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
// 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
{
return 50;
}
附:对于单列选择器,只要控制UIPickerView的dataSource对象的numberOfComponentsInPickerView:方法返回1即可。
- 选择器的使用——郭挺
- jQuery的选择器—层次选择器
- java编程心得(三)——文件选择器的使用
- 使用过的CSS元素整理——选择器
- jQuery 选择器的使用
- jquery选择器的使用
- jQuery 选择器的使用
- jQuery 选择器的使用
- jQuery 选择器的使用
- jQuery 选择器的使用
- JQuery的选择器使用
- IOS选择器的使用
- Jquery----------选择器的使用
- 选择器的使用
- Selector选择器的使用
- jQuery选择器的使用
- selector选择器的使用
- 日期选择器的使用
- 八数码宽度优先算法
- mac下vim半透明设置
- Android自助餐之Fragment与Activity通信
- 关于新手对于json的一些话
- Ubuntu14.04 vsftpd安装与配置
- 选择器的使用——郭挺
- HDU ACM组队安排 [基础DP+打表]
- Multi-task
- 【Swing】 事件处理+actionlistener
- Lua封装增加CCEditBox编辑框接口
- 私有化构造函数的作用
- tomcat CATALINA_BASE环境变量配置
- 从零开始写javaweb框架笔记6-需求分析与系统设计
- 【2015HDU11月校赛(新生赛)ABCDEFGH题解】