在选取器视图中未选择第一个值
你好 我在单击一个按钮选择器视图时有一些按钮,但如果滚动则不会选择第一个值,然后只选择第一个值,所以请帮助我,
这是我的代码,
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (tagVlaue) {
case 0:
{
if(gender==YES)
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [checkArray objectAtIndex:row], row);
selectedgender=[checkArray objectAtIndex:row];
NSLog(@"selected checkgender %@",selectedgender);
genderlabel.text=selectedgender;
// checkgender=NO;
}
else
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [genderArray objectAtIndex:row], row);
selectedgender=[genderArray objectAtIndex:row];
NSLog(@"selected gender %@",selectedgender);
genderlabel.text=selectedgender;
// checkgender=YES;
}
//genderlabel
}
break;
case 1:
{
if(gender==NO)
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [seekingArray objectAtIndex:row], row);
selectedseek=[seekingArray objectAtIndex:row];
NSLog(@"selected seeking %@",selectedseek);
seeklabel.text=selectedseek;
}
else {
NSLog(@"Selected Color: %@. Index of selected color: %i", [seekCheckArray objectAtIndex:row], row);
selectedseek=[seekCheckArray objectAtIndex:row];
NSLog(@"selected seeking %@",selectedseek);
seeklabel.text=selectedseek;
}
}
break;
case 2:
NSLog(@"Selected Color: %@. Index of selected color: %i", [ageArray objectAtIndex:row], row);
selectedage=[ageArray objectAtIndex:row];
NSLog(@"selected age %@",selectedage);
label.text=selectedage;
break;
case 3:
NSLog(@"Selected Color: %@. Index of selected color: %i", [feetArray objectAtIndex:row], row);
selectedheight=[feetArray objectAtIndex:row];
NSLog(@"selected height %@",selectedheight);
heightlabel.text=selectedheight;
break;
case 4:
NSLog(@"Selected Color: %@. Index of selected color: %i", [weightArray objectAtIndex:row], row);
selectedweight=[weightArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedweight);
weightlabel.text=selectedweight;
break;
case 5:
NSLog(@"Selected Color: %@. Index of selected color: %i", [enthnicityArray objectAtIndex:row],row);
selectedethnicity=[enthnicityArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedethnicity);
ethnicitylabel.text=selectedethnicity;
break;
case 6:
NSLog(@"Selected Color: %@. Index of selected color: %i", [typeArray objectAtIndex:row],row);
selectedtype=[typeArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedtype);
typelabel.text=selectedtype;
break;
default:
break;
}
谢谢您的提前
Hi
iam having some buttons when click one button picker view apper but does not select the first value if it scroll then only fist value selected so plz help me
here is my code
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (tagVlaue) {
case 0:
{
if(gender==YES)
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [checkArray objectAtIndex:row], row);
selectedgender=[checkArray objectAtIndex:row];
NSLog(@"selected checkgender %@",selectedgender);
genderlabel.text=selectedgender;
// checkgender=NO;
}
else
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [genderArray objectAtIndex:row], row);
selectedgender=[genderArray objectAtIndex:row];
NSLog(@"selected gender %@",selectedgender);
genderlabel.text=selectedgender;
// checkgender=YES;
}
//genderlabel
}
break;
case 1:
{
if(gender==NO)
{
NSLog(@"Selected Color: %@. Index of selected color: %i", [seekingArray objectAtIndex:row], row);
selectedseek=[seekingArray objectAtIndex:row];
NSLog(@"selected seeking %@",selectedseek);
seeklabel.text=selectedseek;
}
else {
NSLog(@"Selected Color: %@. Index of selected color: %i", [seekCheckArray objectAtIndex:row], row);
selectedseek=[seekCheckArray objectAtIndex:row];
NSLog(@"selected seeking %@",selectedseek);
seeklabel.text=selectedseek;
}
}
break;
case 2:
NSLog(@"Selected Color: %@. Index of selected color: %i", [ageArray objectAtIndex:row], row);
selectedage=[ageArray objectAtIndex:row];
NSLog(@"selected age %@",selectedage);
label.text=selectedage;
break;
case 3:
NSLog(@"Selected Color: %@. Index of selected color: %i", [feetArray objectAtIndex:row], row);
selectedheight=[feetArray objectAtIndex:row];
NSLog(@"selected height %@",selectedheight);
heightlabel.text=selectedheight;
break;
case 4:
NSLog(@"Selected Color: %@. Index of selected color: %i", [weightArray objectAtIndex:row], row);
selectedweight=[weightArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedweight);
weightlabel.text=selectedweight;
break;
case 5:
NSLog(@"Selected Color: %@. Index of selected color: %i", [enthnicityArray objectAtIndex:row],row);
selectedethnicity=[enthnicityArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedethnicity);
ethnicitylabel.text=selectedethnicity;
break;
case 6:
NSLog(@"Selected Color: %@. Index of selected color: %i", [typeArray objectAtIndex:row],row);
selectedtype=[typeArray objectAtIndex:row];
NSLog(@"selected weight %@",selectedtype);
typelabel.text=selectedtype;
break;
default:
break;
}
thanks for advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
委托方法:
仅当用户在选择器中显式选择值时调用。您必须获取自己首次显示选择器时在选择器中选择的值。例如,您可以查看选择器数据源。
The delegate method:
is called only when the user explicitly select the value in the picker. You must get the value that is selected in the picker when the picker is first displayed by yourself. For example you can look at the picker data source.
使用 UIPickerViewDelegate
– pickerView:didSelectRow:inComponent:
的委托方法来了解哪一行已被选择,如果用户没有选择任何内容,则不会调用该方法。Use the delegate method of UIPickerViewDelegate
– pickerView:didSelectRow:inComponent:
to know which row has been selected if nothing is selected by the user this won't be called.