IOS pickerView 使用
来源:互联网 发布:linux查看所有进程命令 编辑:程序博客网 时间:2024/04/28 11:22
源码下载
选择器,如同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 使用
- iOS pickerView
- ios学习之pickerview的使用
- 适合IOS新手的pickerView使用
- 使用PickerView
- Android使用wheelView实现简单类似ios PickerView选择器效果
- iOS 自定义PickerView
- ios pickerView 点菜
- ios pickerview选择城市
- iOS tableView和pickerView
- 仿ios的PickerView
- Android-PickerView的使用
- ios-day10-02(UIPickerView的使用。使用xib自定义pickerView每一行显示的view)
- PickerView
- PickerView
- pickerView
- PickerView
- PickerView
- SylixOS ARM BSP 第二篇【startup.S】
- POJ 1011 Sticks(dfs)
- HTML中meta标签详解
- 收到一位同学的来信,问8168的问题,回答如下
- centos下varnish的安装
- IOS pickerView 使用
- 大型网站的灵魂——性能
- JavaScript基础一 简介、入门、事件、变量
- 拓扑排序
- hbase权威指南阅读随手笔记二之过滤器
- centos 按装卸载mysql
- Bjarne Stroustrup对C++程序员的忠告
- Android应用开发多语言Value文件夹
- 怎么对高八位或低八位写值而不影响其它位,还有怎样单独读取高八位或低八位的值