iOS 基础小结之常用控件三
来源:互联网 发布:查看linux用户密码 编辑:程序博客网 时间:2024/06/01 10:13
UIPickerView
(1)
先声明要用的协议<UIPickerViewDataSource,UIPickerViewDelegate>
声明变量
@property (strong,nonatomic)NSArray * books;
@property (strong,nonatomic)NSArray * authors;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
- (void)viewDidLoad
{
[superviewDidLoad];
_authors = [NSArrayarrayWithObjects:@"li",@"zhang", @"liu",nil];
_books = [NSArrayarrayWithObjects:@"111",@"222", @"333",nil];
self.picker.dataSource =self;
self.picker.delegate =self;
}
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;//两列,有几列返回几
}
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component == 0) {
return_authors.count;
}
return_books.count;
}//返回每一列的数目
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0) {
return [_authorsobjectAtIndex:row];
}
return [_booksobjectAtIndex:row];
}//返回选择的列的选择的行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSArray * tmp = component == 0 ? _authors : _books;
NSString * tip = component == 0 ? @"authers " : @"books";
UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"notice"message:[NSStringstringWithFormat:@"you have chose %@ : %@",tip,[tmpobjectAtIndex:row]] delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];
[alert show];
}//获取选择的内容
(2)相互依赖的Picker@property (strong,nonatomic)NSDictionary * books;
@property (strong,nonatomic)NSArray * authors;
@property (strong,nonatomic)NSString * selectedAuthor;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
- (void)viewDidLoad
{
[superviewDidLoad];
_books = [NSDictionarydictionaryWithObjectsAndKeys:[NSArrayarrayWithObjects:@"111",@"222",nil],@"li", [NSArrayarrayWithObjects:@"333",@"444",nil],@"zhang", [NSArrayarrayWithObjects:@"555",@"666", @"777",nil],@"liu",nil];
_authors = [[_booksallKeys]sortedArrayUsingSelector:@selector(compare:)];
_selectedAuthor = [_authorsobjectAtIndex:0];
self.picker.dataSource =self;
self.picker.delegate =self;
}
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component == 0) {
return_authors.count;
}
return [[_booksobjectForKey:_selectedAuthor]count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == 0) {
return [_authorsobjectAtIndex:row];
}
return [[_booksobjectForKey:_selectedAuthor] objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if (component == 0) {
_selectedAuthor = [_authorsobjectAtIndex:row];
[self.pickerreloadComponent:1];
}
NSArray * tmp = component ==0 ? _authors : [_booksobjectForKey:_selectedAuthor];
NSString * tip = component == 0 ? @"auther" : @"books";
UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"notice"message:[NSStringstringWithFormat:@"you have chose %@ : %@",tip,[tmpobjectAtIndex:row]] delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];
[alert show];
}
- iOS 基础小结之常用控件三
- iOS 基础小结之常用控件 一
- iOS 基础小结 常用控件之二
- iOS开发之三:常用控件--UILabel的使用
- iOS基础之OC简单控件知识了解(三)
- ios基础控件之UITextField常用方法汇总
- iOS基础常用控件简介
- iOS基础控件之UISegmentedControl
- ios基础控件之UITextView
- IOS 控件之基础整理
- IOS之基础控件(一)
- 学习ios之基础控件
- iOS 开发基础常用控件介绍总结
- iOS基础控件:UIScrollView 之三大属性 contentOffset 、contentSize 、contentInset 之间的区别
- iOS开发UI基础—25UITableview控件使用小结
- iOS开发UI基础—10常用UI控件综合示例之QQ音乐
- wpf 常用控件 总结之三
- IOS5基础教程之三-----常用控件属性
- How to Install Oracle 12C Enterprise Edition Database Ubuntu 13.10
- 快速入门C++ 07(构造器和析构器)
- ajax异步提交含有文件的表单
- 实验室基础信息系统
- 静态变量基础
- iOS 基础小结之常用控件三
- QTP退出函数
- Loadrunner中Socket协议接收定长和不定长的内容
- C语言链表各类操作详解
- 乱码java.io.CharConversionException: isHexDigit
- al11 写数据到SAP
- 清除解锁图案 首先执行cd data/system进入系统文件目录,执行ls列举文件目录,这里有三个与用户相关的文件accounts.db(gmail账号管理),gesture.key(手势识别文件)
- 百度地图api 常用 例子
- 解决MyEclipse中导入项目@Override错误