标签:视图 ber 设置 loaddata nsstring nts make 指定 int
(一)初始化
1、创建
UIPickerView * picViewBid = [[UIPickerView alloc]initWithFrame:CGRectMake(rect.size.width/2-10,lblBid.frame.origin.y-40, 150, 120)];
2、设置数据源及委托
picViewBid.delegate = self; picViewBid.dataSource = self;
注:需要在.h文件中加<UIPickerViewDelegate>,如:
@interface starViewController<UIPickerViewDelegate>: UIViewController { CGRect rect; } @end
3、加入视图
[bgTopView addSubview:picViewBid];
(二)委托实现
1、设置展示数据:数据以数组的形式保存
-(void)loadData{ pickerCon = @[@"11",@"222",@"333"]; }
2、指定pickerview有几个表盘
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; }
3、指定每个表盘上有几行数据
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return 3; }
4、指定每行如何展示数据
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ // title = pickerCon[row]; switch (row) { case 0: return @"6.v"; break; case 1: return @"goodshow"; break; case 2: return @"sixshow"; default: break; } return pickerCon[row]; }
标签:视图 ber 设置 loaddata nsstring nts make 指定 int
原文地址:http://www.cnblogs.com/Asssjc/p/6004847.html