简体   繁体   English

当UITextField开始编辑时,UIPickerView不显示为输入视图

[英]UIPickerView isn't showing as inputview when UITextField begins to edit

I have managed to add a UIPickerView as an input view to UITextField in viewDidLoad, but now I want to make the UITextField as first responder when another textfield (with tag =4) ends editing. 我已经设法在viewDidLoad中将UIPickerView作为输入视图添加到UITextField,但是现在我想在另一个文本字段(标记= 4)结束编辑时将UITextField作为第一响应者。 This is the code I'm using: 这是我正在使用的代码:

This is in the viewdidload, and all the other code needed to initialize the picker view is there: 这是在viewdidload中,初始化选择器视图所需的所有其他代码都在那里:

 UIPickerView *myPickerView = [[UIPickerView alloc] init];
    myPickerView.showsSelectionIndicator = YES;
    myPickerView.delegate = self;
    myPickerView.dataSource = self;
   myPickerView.backgroundColor = [UIColor colorWithRed:76/255.0 green:76/255.0 blue:76/255.0 alpha:1];
    textfieldInput.inputView = myPickerView;

This is in my text field did end editing method: 这是在我的文本字段中做了结束编辑方法:

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if(textField.tag == 4){
        [textfieldInput becomeFirstResponder];
    }

The problem is that when the textfieldInput becomes the first responder, the picker view isn't shown, instead the keyboard is presented. 问题是当textfieldInput成为第一个响应者时,未显示选择器视图,而是显示键盘。 Also, it should be mentioned that i have another textfield on top of this that gets resigned if it became the first responder and becomes hidden. 此外,应该提到的是,如果它成为第一个响应者并且变得隐藏,我在此之上还有另一个文本字段被取消。 This textfield is the textfield that has a tag of 4. (This textfield has been added for design reasons). 此文本字段是标记为4的文本字段。(出于设计原因添加了此文本字段)。

This code works for me... are you sure that call the correct reference of textfield? 这段代码对我有用......你确定调用textfield的正确引用吗?

try: [self.textfield becomeFirstResponder]; 尝试: [self.textfield becomeFirstResponder];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM