iOS UIPickerview在didSelectRow中消失

时间:2015-04-12 17:11:13

标签: ios objective-c uipickerview

iOS 8
Xcode 6.3
我有一个选择器视图,它有2个组件。一旦用户点击文本字段,我就会带上选择器视图。 一旦用户在选择器视图中选择一个值,它就会消失! 请参阅以下代码:

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

如果我没有设置文本字段的值它正常工作并且不会消失,但如果我设置了textfield的值,那么它就会消失。谁能说出为什么会这样?

2 个答案:

答案 0 :(得分:0)

我认为你正在尝试做类似的事情,我有类似的问题而且只在ios 8上。 也检查这个问题iOS8: What's going on with moving views during keyboard transitions? 不要使用故事板

//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];

按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];
      }
  }

现在在' pickerView didSelectRow'你的挑选者观点不会消失 希望这有帮助

答案 1 :(得分:0)

感谢您的回复。但是,我在一周前联系了Apple技术支持,最后他们回复了。 以下是他们的建议:

  

选择完成后UIPickerView的问题消失可能是一个错误。请考虑在http://bugreport.apple.com提交错误报告,并附上您的示例项目。作为解决方法,请以编程方式创建选择器视图和工具栏,并且仅在需要时创建。

我还没有尝试手动添加选择器,但我已经提交了错误报告。一旦修好,我会在这里更新。