iOS基础 -- UIPickerView
来源:互联网 发布:kali linux dsdt 编辑:程序博客网 时间:2024/05/07 14:06
self.myPick = [[UIPickerView alloc] init]; self.myPick.center = self.view.center; self.myPick.dataSource = self; self.myPick.delegate = self; //[self.myPick reloadAllComponents]; //[self.myPick reloadComponent:1]; [self.view addSubview:self.myPick];
如上,添加pickView到当前view,UIPickerView需要实现两个协议,一个是用户显示的UIPickerViewDataSource,一个是用于操作的UIPickerViewDelegate。
UIPickerViewDataSource主要实现以下两个方法:
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{ if([pickerView isEqual:self.myPick]) return 1; return 0;}-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ if([pickerView isEqual: self.myPick]) return 10; return 0;}
主要用于确定UIPickerView的列数和行数。
UIPickerViewDelegate主要实现以下几个方法:
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ //NSLog(@"%d",[self.myPick selectedRowInComponent:0]); if([pickerView isEqual:self.myPick]) return [NSString stringWithFormat:@"Row %ld",(long)row+1]; return nil;}-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ NSLog(@"what you selected is row: %d,component: %d",row,component);}
用于确定显示的内容,以及监控pickerView的选择。
UIPicker在iOS7 中和viewController的背景一样都是白色的。iOS6或者更低版本中可以通过设置showSelectionIndicator为YES,来高亮显示当前的selection。
[self.myPicker setShowSelectionIndicator:YES];
0 0
- iOS基础 -- UIPickerView
- ios开发基础视图 - UIPickerView
- IOS开发基础UIPickerView循环显示
- iOS UIPickerView
- iOS UIPickerView
- iOS UIPickerView
- IOS UIPickerView
- IOS UIPickerView
- IOS基础UI之(十) UIPickerView和UIDatePicker详解
- iOS开发之基础视图—— UIPickerView
- ios iphone 自定义UIPickerView
- iOS开发:UIPickerView控件
- IOS UIPickerView使用
- iOS开发:UIPickerView控件
- iOS编程之UIPickerView
- iOS uipickerview 选择DATE
- xamarin.ios uipickerview
- IOS UIPickerView 学习笔记
- 多文件修改版
- android调试是出现:Re-installation failed due to different application signatures
- TrustZone——例子程序—FastModels和QEMU测试
- 生病不爽呢
- POJ-1930-Dead Fraction
- iOS基础 -- UIPickerView
- undo异常总结和恢复思路
- 让easyUI TAB页随页面内的按钮事件变化
- 解决typedef unsigned long long DDWORD; 在VC下编译不过问题。
- FZU2154 Problem 2154 YesOrNo
- Apache2.2 Tomcat6.0.36 64位集群
- 键盘技巧系列——Keil uVision4
- 培养阅读习惯的六个建议
- 多线程和网络通信实现的简单文件下载