简体   繁体   中英

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. 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:

 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. 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).

This code works for me... are you sure that call the correct reference of textfield?

try: [self.textfield becomeFirstResponder];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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