0

This is my code but its not working properly

I want to select first row value when i press the done button

I tried this code, there are two views and and in each view there are two pickers,

if i select the firstPickerView value of first row then the 2nd picker first value automatically changed,

I don't know what to do or how to solve this issue

Please Help Me i am new in this programing need your support

Here is my code:

- (IBAction)pickerViewDoneBtn:(id)sender {

    if (self.amountScratchView) {

        [self myViewDown:self.amountScratchView];

        [self.amountScratchView removeFromSuperview];
    }

   if (self.operatorScratchView) {

        [self myViewDown:self.operatorScratchView];

        [self.operatorScratchView removeFromSuperview];
    }

   if (self.topUpOperatorView) {

      [self.operatorLbl setText:[NSString stringWithFormat:@"%@", [operatorDataArray 

objectAtIndex:[self.topUpPickerView selectedRowInComponent:0]]]];

        [self myViewDown:self.topUpOperatorView];

        [self.topUpOperatorView removeFromSuperview];
    }
   if (self.topUpAmountView) {

        [self.amountLbl setText:[NSString stringWithFormat:@"%@", [amountDataArray 

objectAtIndex:[self.topUpAmountPickerView selectedRowInComponent:0]]]];


        [self myViewDown:self.topUpAmountView];

        [self.topUpAmountView removeFromSuperview];
    }

}

OR please tell me how to select the first value in row in upickerview

Civa
  • 2,058
  • 2
  • 18
  • 30

1 Answers1

1

You can easily write following code to select first row in pickerView as give code below.

 [picker selectRow:0 inComponent:0 animated:YES];

set this code in your done button action.Here picker is pickerView outlet

you can also use delegate method to select row as

picker.delegate=self;

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"selected row is %i",row);
}

prefer this link Select first row

Community
  • 1
  • 1
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90