在选择器视图中不选择1St值

时间:2011-05-11 07:10:41

标签: iphone ios uipickerview

您好 单击一个按钮选择器视图时有一些按钮,但如果滚动则不选择第一个值,然后只选择第一个值,这样plz帮助我

这是我的代码

- (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;
}

感谢提前

2 个答案:

答案 0 :(得分:1)

委托方法:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
仅当用户明确选择选择器中的值时才会调用

。当您首次显示选择器时,您必须获取选择器中选择的值。例如,您可以查看选择器数据源。

答案 1 :(得分:0)

使用UIPickerViewDelegate – pickerView:didSelectRow:inComponent:的委托方法知道如果用户没有选择任何行,则会选择哪一行,这将不会被调用。