0

iOS 8
Xcode 6.3
I have a picker view which has 2 components. I bring the picker view once user clicked on a textfield. Once user selects a value in picker view it disappears! Please see code below:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        ccYearTF.text = [NSString stringWithFormat:@"%i", [pickerView selectedRowInComponent:0] + 2015];
    }
    else {
        ccMonthTF.text = [NSString stringWithFormat:@"%02d", [pickerView selectedRowInComponent:1] + 1];
    }
}

If I don't set value of the textfields it works normally and doesn't disappear, but if I set textfield's value then it disappears. Who can tell why is this happening?

Artin
  • 241
  • 4
  • 9
  • Is the picker view the text field's `inputView`? Is the text field resigning first responder (that will hide the input view)? – rmaddy Apr 12 '15 at 17:19
  • picker view is not text field's inputView. I just bring up picker view animated when text field is tapped. And when select a value from picker I set that to text field. – Artin Apr 12 '15 at 19:23
  • Can you show us the code for the TextField delegate? What's happening when textField become first responder, and also when it calls: shouldChangeText. – pteofil May 05 '15 at 12:21

2 Answers2

1

i think you are trying to do something like that, i had similar problem and only on ios 8. Check this question too iOS8: What's going on with moving views during keyboard transitions? Do not use storyboard

//Do not link with storyboard
@property UIPickerView *pickerview;
//in view didload
self.pickerview = [[UIPickerView alloc] initWithFrame:CGRectMake(self.view.frame.size.width+1,ccYearTF.frame.origin.y+60,self.view.frame.size.width, 150)];
self.pickerview.dataSource = self;
self.pickerview.delegate = self;
[self.view addSubview:self.pickerview];

when you press ccYearTf textfiled

  -(void)textFieldDidBeginEditing:(UITextField *)textField
  {
     if(textField == ccYearTf )
     { 
         [textField resignFirstResponder];
         [UIView animateWithDuration:0.7f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
             [self.pickerview setFrame:CGRectMake(0, _pickerview.frame.origin.y, self.view.frame.size.width, _pickerview.frame.size.height)];
         }completion:nil];
      }
  }

now on 'pickerView didSelectRow' your pickerview wont disappear hope this helps

Community
  • 1
  • 1
Cwnstantin
  • 9
  • 1
  • 2
0

Thanks for your replies. However, I've contacted Apple technical support a week ago and finally they replied. Here is what they suggested:

The issue of the UIPickerView disappearing when a selection has been made may be a bug. Please consider filing a bug report at http://bugreport.apple.com, and attach your sample project. As a workaround, please create the picker view and the toolbar programmatically, and only as needed.

I haven't tried to add the picker manually yet, but I've submitted a bug report. I'll update here once fixed.

Artin
  • 241
  • 4
  • 9