标签:
//初始化:
TimesPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
CGRect pickerRect = CGRectMake(w, h, x, y);
TimesPickerView.frame = pickerRect;
TimesPickerView.showsSelectionIndicator = YES;
[TimesPickerView setBackgroundColor:[UIColor clearColor]];
TimesPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
TimesPickerView.delegate=self; //设置委托
[self.view addSubview:TimesPickerView]; //设置默认值,3可以用变量代替,保存数据
[TimesPickerView selectRow:3 inComponent:0 animated:YES];
//选项默认值
-(void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
-
{
return;
}
//设置列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}
//返回数组总数
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
return [pickerViewsarray count];//将数据建立一个数组
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)rowforComponent:(NSInteger)component
{ return [pickerViewsarray objectAtIndex:row];
if(row==1)
{ return [pickerViewsarray objectAtIndex:1];
}
}
//触发事件
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{ [pickerViewsarray objectAtIndex:row];
switch (row)
{ case 0: NSLog(@"row:%d",row);
break;
case 1: NSLog(@"row:%d",row);
break;
}
标签:
原文地址:http://www.cnblogs.com/sancaixu/p/4574897.html