UIPickerView 多级联动
UIPickerView的多级联动问题有些地方需要注意,其实多级联动并不难。。。楼主因为项目需要又没法使用网上的第三方,所以最近写了一个省市区多级联动,还是手写代码好!!
为了演示效果,我会多定义几个属性,表现演示效果
@interface newTeamSettingController()<UIPickerViewDataSource,UIPickerViewDelegate>
@property(strong,nonatomic)NSString* strWeek;//记录周数
@property(strong,nonatomic)NSString* strTime;//记录时辰
@property(strong,nonatomic)NSArray* timeArray;//数组保存
@property(strong,nonatomic)UITextField* timeField;
@end
初始化,使textField一开始显示数据
- (void)viewDidLoad {
//初始化timeArray
NSArray* weekArray=@[@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",@"周日"];
NSArray* shijianArray=@[@"上午",@"下午",@"晚上"];
self.timeArray=[NSArray arrayWithObjects:weekArray,shijianArray, nil];
//请选择的时间textField
self.timeField=[[UITextField alloc]initWithFrame:CGRectMake(*luScaleW, *luScaleH, *luScaleW, *luScaleH)];
self.timeField.tag=;
self.timeField.placeholder=@"请选择";
self.timeField.textAlignment=NSTextAlignmentRight;
self.timeField.adjustsFontSizeToFitWidth=YES;
self.strWeek=[NSString stringWithFormat:@"%@",self.timeArray[][]];
self.strTime=[NSString stringWithFormat:@"%@",self.timeArray[][]];
[self.chuZhenView addSubview:self.timeField];
//timePickerView
self.timePickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(, CGRectGetMaxY(self.timeField.frame), LuW, )];
self.timePickerView.tag=;
self.timePickerView.dataSource=self;
self.timePickerView.delegate=self;
self.timeField.delegate=self;
self.timeField.inputView=self.timePickerView;
//在这里设置下方数据刷新部分的初始显示
for (int component = ; component<self.timeArray.count; component++) {
[self pickerView:nil didSelectRow: inComponent:component];
}
[self pickerView:nil didSelectRow: inComponent:];
self.doneBtn=[[UIToolbar alloc]initWithFrame:CGRectMake(, , LuW, )];
UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem* rightBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneClick)];
self.doneBtn.items=[NSArray arrayWithObjects:button1,rightBtn, nil];
self.timeField.inputAccessoryView=self.doneBtn;
}
UIPickerView的代理方法
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return self.timeArray.count;
}
//每列对应多少行
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSArray* arryM=self.timeArray[component];
return arryM.count;
}
//每行对应显示的数据是什么
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSArray* arrayM=self.timeArray[component];
NSString* name=arrayM[row];
return name;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component==) {
[pickerView reloadComponent:];
[pickerView selectRow: inComponent: animated:YES];
_strWeek=self.timeArray[component][row];
_strTime=self.timeArray[][];
}
else
{
_strTime=self.timeArray[component][row];
}
self.timeField.text=[NSString stringWithFormat:@"%@ %@",_strWeek,_strTime];
}
完成。
UIPickerView 多级联动的更多相关文章
- 微信小程序-多级联动
微信小程序中的多级联动 这里用到的案例是城市选择器 先上代码: .wxml <view class="{{boxHide}}"> <view>{{nian} ...
- PHP多级联动的学习(一)
我尝试在ThinkCMF中实现多级联动,首先我开始看了dede的联动类别管理前后台的代码以及他的数据库,经过非常多次的尝试,我渐渐有了一点想法,并给予实施. 首先写出前台的界面.如图. 然后在数据库中 ...
- vue在多级联动时,一些情况不用watch而用onchange会更好
onchange事件在内容改变且失去焦点时触发,因此在一些多级联动需要清空次级内容的时候,用onchange就非常有用了,尤其是浏览器会提前加载数据的情况下.有篇文章可以看一下,链接. PS:路漫漫其 ...
- [ PHP+jQuery ] ajax 多级联动菜单的应用:电商网站的用户地址选择功能 ( 二 ) - 仿亚马逊下拉面板
/** jQuery version: 1.8.3 Author: 小dee Date: 2014.11.8 */ 接上一篇博客. 实现带缓存的仿亚马逊下拉面板 效果图: 图1 初始 图2 点击省份 ...
- DropDownList的多级联动
DropDownList的多级联动的问题最典型的案例就是实现省市级三级联动的案例,对这个问题的描述是当选中山东省之后,在选择市的下拉菜单时,市一栏只出现山东省下面的市.对于县也是同样的道理. 我也做的 ...
- jQuery cxSelect 多级联动下拉菜单
随着电商热门,这种多层次的互动更充分地体现在下拉菜单,最明显的是多级联动地址下拉选择,因此,这里是一个简单的分享 jQuery cxSelect 多级联动下拉菜单 cxSelect 它是基于 jQue ...
- jQuery插件——多级联动菜单
jQuery插件——多级联动菜单 引言 开发中,有好多地方用到联动菜单,以前每次遇到联动菜单的时候都去重新写,代码重用率很低,前几天又遇到联动菜单的问题,总结了下,发现可以开发一个联动菜单的功能,以后 ...
- JavaScript 多级联动浮动(下拉)菜单 (第二版)
JavaScript 多级联动浮动(下拉)菜单 (第二版) 上一个版本(第一版请看这里)基本实现了多级联动和浮动菜单的功能,但效果不是太好,使用麻烦还有些bug,实用性不高.这次除了修改已发现的问 ...
- MVC实现多级联动
前言 多级联动(省级联动)的效果,网上现成的都有很多,各种JS实现,Jquery实现等等,今天我们要讲的是在MVC里面,如何更方便.更轻量的实现省级联动呢? 实现效果如下: 具体实现 如图所示,在HT ...
随机推荐
- 谈谈hibernate的缓存
一,hibernate是什么技术? 1 hibernate是一个orm 就是对象关系映射框架. 及我们创建的实体类对象与数据库表中的数据是一一对应的关系. 我们可以改变对象信息从而改变数据库中的 ...
- Eclipse-Java代码规范和质量检查插件-PMD
PMD是一个源代码分析器. 它发现常见的编程缺陷,如未使用的变量.空catch块.不必要的对象创建等等. 它支持Java.JavaScript.Salesforce.com Apex.PLSQL.Ap ...
- Ubuntu系统备份工具大全(官方整理推荐)
其实官方在系统备份这块已经有Wiki整理和收集各类实用的工具.以下是翻译自官方Wiki的部分文档: 备份工具 wiki文档实用程序 工具 界面 格式类型 Raw/File 支持 远程 增量 差异 自 ...
- mysql转oracle注意事项
1.mysql中有自增长,oracle用新建sequence代替. 2.在实体类的id要指定相关的sequence @GeneratedValue(strategy=GenerationType.SE ...
- MongoDB小结04 - update【$inc】
update方法很强大,它有两个参数,一是查询文档,用来找出需要更新的文档,另一个是修改器(modifier)文档,描述对找到的文档做哪些修改. 亮点 更新操作是原子的,若两个更新同时发生,先到达服务 ...
- 解决fragmentTransaction.replace不能全屏
今天遇到个问题,使用fragmentTransaction.replace替换后的内容不能全屏.. FragmentManager fragmentManager = getSupportFragme ...
- python爬虫实践--求职Top10城市
前言 从智联招聘爬取相关信息后,我们关心的是如何对内容进行分析,获取用用的信息.本次以上篇文章“5分钟掌握智联招聘网站爬取并保存到MongoDB数据库”中爬取的数据为基础,分析关键词为“python” ...
- react 中的 setState
语法:setState(newState [,callback]) 1.只要有入门基础的同学都知道 setState({...}) 是更新组件中的 state 内容 2.但是,setState 是异步 ...
- TensorFlow的安装与CNN测试
0.说明 在Google开源该框架之后便使用真实K40m卡测试,由于生产环境是CentOS6.6的操作系统,但是该框架需要在Python2.7环境下执行,CentOS6.6下折腾了一天没搞定,后来换成 ...
- js生成页面水印
路: 获取想要插入水印的文档节点的顶点坐标值x,y. 获取文档节点的高度heigt和宽度width. 用div包裹文字来生成水印. 定义好div的长宽高间距等各种属性. 定义虚拟节点createDoc ...