2015-04-12 120 views
0

iOS 8
Xcode 6.3
我有一个选择器视图,它有2个组件。一旦用户点击文本框,我就会带来选择器视图。 一旦用户在选取器视图中选择一个值,它就会消失! 请参见下面的代码:iOS的UIPickerview消失在didSelectRow

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

如果我不把它正常工作,并不会消失的文本框的值,但如果我设置文本框的值,然后消失。谁能说出为什么会发生这种情况?

+0

拾取器是否查看文本字段的'inputView'?文本字段是否退出第一响应者(将隐藏输入视图)? – rmaddy

+0

选择器视图不是文本字段的inputView。我只是在文本字段被点击时调出选择器视图。当从选择器中选择一个值时,我将其设置为文本字段。 – Artin

+0

你能告诉我们TextField委托的代码吗?当textField成为第一响应者时,以及在它调用shouldChangeText时发生了什么。 – pteofil

回答

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' 你pickerview不会消失 希望这有助于

0

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

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

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