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];
}
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:
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.