源码下载

选择器,如同html select 一个pickerView可以实现多个select 关键是由numberOfComponentsInPickerView 这个决定有多少个列

实现委托和数据源。

实现下面三个方法

// 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 [array1 count];

}else{;

return [array2 count];

}

}

//设置当前内容

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{

if(component==0){

return [array1 objectAtIndex:row];

}else{

return [array2 objectAtIndex:row];

}

}

实现效果:

获取选择到的数据

联动效果

需要定义一个字典类型。相当于java Map类型

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

NSLog(@"DDDDD");

mainArray = [NSArray arrayWithObjects:@"test1",@"test2",nil];

myds = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObjects:@"test11",@"test12", nil],@"test1",

[NSArray arrayWithObjects:@"test21",@"test22", nil],@"test2", nil];

subArray = [myds objectForKey:@"test1"];

_pick4.delegate=self;

_pick4.dataSource=self;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

// 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 [mainArray count];

}else{;

return [subArray count];

}

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{

if(component==0){

return [mainArray objectAtIndex:row];

}else{

return [subArray objectAtIndex:row];

}

}

//选择相应列表的时候

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

if(component==0){

subArray  = [myds objectForKey:[mainArray objectAtIndex:row]];

[pickerView selectRow:0 inComponent:1 animated:YES];

[pickerView reloadComponent:1 ];

}

}

//实现读取内容

- (IBAction)button4click:(id)sender {

_text4.text = @"DDDD";

NSInteger ar1 = [_pick4 selectedRowInComponent:0];

NSInteger ar2 = [_pick4 selectedRowInComponent:1];

NSString *str1 = [mainArray objectAtIndex:ar1];

NSString *str2 = [subArray objectAtIndex:ar2];

NSString *message  = [ str1  stringByAppendingFormat:@"---%@",str2  ];

_text4.text = message;

}

IOS pickerView 使用相关推荐

  1. iOS pickerView(所有类型一网打尽)

    概述 关于PickView的所有类型都在这里 详细 代码下载:http://www.demodashi.com/demo/11017.html 首先看下项目的整体结构: 一.准备工作 UIPicker ...

  2. ios pickerview选择城市

    // // ViewController.m // 02-城市选中 // // Created by panba on 16-4-12. // Copyright (c) 2016年 panba. A ...

  3. 安卓开源项目周报1220

    由OpenDigg 出品的安卓开源项目周报第二期来啦.我们的安卓开源周报集合了OpenDigg一周来新收录的优质的安卓开发方面的开源项目,方便安卓开发人员便捷的找到自己需要的项目工具等. androi ...

  4. 最全android Demo

    1.BeautifulRefreshLayout-漂亮的美食下拉刷新 https://github.com/android-cjj/BeautifulRefreshLayout/tree/Beauti ...

  5. 140款Android开源优秀项目源码

    140款Android开源优秀项目源码 BeautifulRefreshLayout-漂亮的美食下拉刷新 https://github.com/android-cjj/BeautifulRefresh ...

  6. GitHub 上受欢迎的 Android UI Library 整理(一)

    内容较多,可以用 ctrl+F 来搜索 抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案 https://githu ...

  7. Github常用框架集合

    Script桥接 https://github.com/JackyAndroid/AndroidChromium ★1476 - 谷歌浏览器安卓版源码项目 https://github.com/The ...

  8. GitHub 上受欢迎的 Android UI Library 整理

    抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案 https://github.com/Yalantis/Side- ...

  9. GitHub 上受欢迎的 Android UI Library(part_one)

    抽屉菜单 https://github.com/mikepenz/MaterialDrawer ★7337 - 安卓抽屉效果实现方案 https://github.com/Yalantis/Side- ...

最新文章

  1. CPU 深夜狂飙,一帮大佬都傻眼了......
  2. 无法在终端中显示Git树
  3. python查看环境路径
  4. Qt与OpenCV编程:在QLabel加载的图像上画矩形并剪切
  5. external libraries里没有maven包_Maven企业实战系列(三):彻底看懂maven的体系结构...
  6. 前端常见的安全性问题有哪些?
  7. 使用友盟+的APM服务实现对移动端APP的性能监控
  8. 微信小程序开发教程第八章:微信小程序分组开发与左滑功能实现
  9. 安装注册数据库管理工具
  10. java匿名类对象的坏处_java匿名内部类的使用注意事项
  11. 仿百度的输入提示功能
  12. python+webdriver(二)
  13. su and sudo
  14. 清退117名博士、119名硕士!研究生“严出”成人才培养大趋势
  15. java 集合教程_Java Collections
  16. 2021 年 35+ 最佳免费 WordPress 博客主题
  17. IT公司面试 逻辑题目
  18. 由对称引起的空间结构耦合效应
  19. Invalid row number (65536) outside allowable range (0..65535)
  20. LNK1104:无法打开文件\.obj

热门文章

  1. 机器学习中的损失函数(Loss Function)介绍、说明
  2. java的class文件批量反编译
  3. “藤”缠“树”,腾讯安全与青藤云安全发力主机安全
  4. 网络推广平台有哪些优势?
  5. 通达OA使用手册(一)
  6. Vector-常用CAN工具 - CANoe入门到精通_01
  7. 批量下载ts视频文件
  8. 5G 网络架构(核心网)总结
  9. 计算机网络原理学习资源——相关书籍推荐
  10. 数据结构复习题(线性表)