UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, 320, 216)];
pickerView.showsSelectionIndicator=YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[self.view addSubview:pickerView];
[pickerView release];
_proTimeList = [[NSArray alloc]initWithObjects:@
"1"
,@
"2"
,@
"3"
,@
"4"
,@
"5"
,@
"6"
,@
"7"
,@
"8"
,@
"9"
,@
"10"
,nil];
_proTitleList = [[NSArray alloc]initWithObjects:@
"1"
,@
"2"
,@
"3"
,@
"4"
,@
"5"
,@
"6"
,@
"7"
,@
"8"
,@
"9"
,@
"10"
,nil
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return
2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if
(component == 0) {
return
[_proTitleList count];
}
return
[_proTimeList count];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
if
(component == 1) {
return
40;
}
return
180;
}
- (
void
)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if
(component == 0) {
_proNameStr = [_proTitleList objectAtIndex:row];
}
else
{
_proTimeStr = [_proTimeList objectAtIndex:row];
}
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if
(component == 0) {
return
[_proTitleList objectAtIndex:row];
}
else
{
return
[_proTimeList objectAtIndex:row];
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步