在选取器视图中未选择第一个值

发布于 2024-11-06 05:19:56 字数 3084 浏览 2 评论 0原文

你好 我在单击一个按钮选择器视图时有一些按钮,但如果滚动则不会选择第一个值,然后只选择第一个值,所以请帮助我,

这是我的代码,

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚我心虐我身 2024-11-13 05:19:56

委托方法:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

仅当用户在选择器中显式选择值时调用。您必须获取自己首次显示选择器时在选择器中选择的值。例如,您可以查看选择器数据源。

The delegate method:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

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.

夏了南城 2024-11-13 05:19:56

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文