UIPikerView的属性---iOS-Apple苹果官方文档翻译

本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址

 //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495910.html

本文对应pdf文档下载链接,猛戳—>: UIPikerView的属性.docx
231.0 KB
UIPikerView的属性.pdf
216.9 KB

 

 


UIPikerView的属性
技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
numberOfComponents:返回UIPickerView当前的列数
NSInteger num = _pickerView.numberOfComponents;
NSLog( @"%d", num);
2. - (NSInteger)numberOfRowsInComponent:(NSInteger)component; 返回component列中有多少行。
NSInteger numInCp = [_pickerView numberOfRowsInComponent:0];
NSLog(@"%d",numInCp);
3. -  (CGSize)rowSizeForComponent:(NSInteger)component; 返回component中一行的尺寸。

CGSize size = [_pickerView rowSizeForComponent:0];
NSLog(@"%@", NSStringFromCGSize(size));
pastedGraphic.png

delegate:
2.0 设置UIPickerView代理
_pickerView.delegate = self;
// 设置UIPickView每行显示的内容
2.1 - (
NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
   
 return @"showData";
}
pastedGraphic_1.png

- (
UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

// 返回一个视图,用来设置pickerView的每行显示的内容。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
   
 UIView *myView=[[UIView alloc]init];
    myView.
backgroundColor = [UIColor redColor];
   
 return myView;
}
效果:
pastedGraphic_2.png
dataSource:数据源
#pragma mark  - dataSource method
// 设置每列显示3
- (
NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
   
 return 3;
}
// 设置显示2
-(
NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
   
 return 2;
}

技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
4. showsSelectionIndicator:是否显示指示器,默认为NO  
_pickerView.showsSelectionIndicator = NO;
pastedGraphic_3.png
注意:设置UIPickerView的行数与列数需要设置数据源,遵守
UIPickerViewDataSource,设置UIPickerView的内容需要设置代理,并且遵守代理方法UIPickerViewDelegate

 //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495910.html



5.-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
当点击UIPickerView的某一列中某一行的时候,就会调用这个方法。
6. 返回第component列每一行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView
rowHeightForComponent:(
NSInteger)component;

7.刷新某一列的数据
一旦调用了这个方法,就会重新给数据源发送消息计算这列的行数、重新给代理发送消息获得这列的内容
[pickerView reloadComponent:1];
8. 刷新所有列的数据 
- (void)reloadAllComponents;
9. 返回选中的是第component列的第几行。
- (NSInteger)selectedRowInComponent:(NSInteger)component;                                  


 //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3495910.html

本文对应pdf文档下载链接,猛戳—>: https://www.evernote.com/shard/s227/sh/e83d0f72-0fd5-47e8-8e21-e8034ceec714/0b75653fd46c68671d09afe172099b35

本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址


作者:
出处:http://www.cnblogs.com/ChenYilong/(点击RSS订阅)
本文版权归作者和博客园共有,欢迎转载,
但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/ChenYilong/p/3495910.html