1

I have a UIActionSheet containing a picker and a UIToolbar. On the UIToolBar there is a done button. However, when I spin Picker component and before it stops spinning, if I tap Done button then I'm not getting any value in my UITextfield. If I tap the Done button after picker stops spinning animation, then I'm getting the value of selected component

Is there any way to get value of item before stop Animation..?

SOLVE

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
     UILabel *lbl = (UILabel *)view;

           // Reuse the label if possible...
           if ((lbl == nil) || ([lbl class] != [UILabel class])) {
               CGRect frame = CGRectMake(0.0, 10.0, 250, 50);
               lbl = [[[UILabel alloc] initWithFrame:frame] autorelease];
           }
    if (component == 0) {

        lbl.textColor = [UIColor blackColor];
        lbl.textAlignment=UITextAlignmentLeft;
        lbl.backgroundColor = [UIColor clearColor];



        lbl.text = [arrCountry objectAtIndex:row];
        lbl.font=[UIFont boldSystemFontOfSize:14];
         NSInteger clm1 = [pickerView2 selectedRowInComponent:component];


        txtCountry.text = [arrCountry objectAtIndex:clm1];
        countryCode=[arrCountryCode objectAtIndex:clm1];
    }

    return lbl;
}

and also

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

  txtCountry.text = [arrCountry objectAtIndex:row];
  countryCode=[arrCountryCode objectAtIndex:row];
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144

3 Answers3

2

I don't think you can mate. The UIPicker only calls didselectrow when the spinner has stopped, otherwise it is stuck on previous picked row. the first one in your case.

The closest you can get your functionality using a uipicker is this delegate method:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

You'd have to see what view is on the screen and its offset from the center. Other than that, you can implement your own scrollview and have a uipicker overlay, but that involves a lot of work.

OR! you can tell your users to use the uipicker the proper way lol.

The other way to stop users to pressing save is to detect if the uipicker is spinning or not. I found this to help you.

Community
  • 1
  • 1
mashdup
  • 875
  • 7
  • 18
1

Picker delegate

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    //selectedRowInPicker is globle NSInteger
    selectedRowInPicker = row;
    yourTextField.text = [NSString stringWithFormat:@"%@",[pickerValueAry objectAtIndex:row]];
}

//Done BtnPress

-(void)doneBtnPressToGetValue
{
    yourTextField.text = [NSString stringWithFormat:@"%@",[pickerValueAry objectAtIndex:selectedRowInPicker]];
}
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
0

No. You will only get the value when the picker is stopped. Only at time you will get the picker delegate get called.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200