how to show pickerview in uitextfield not the keyboard?

后端 未结 5 489
旧时难觅i
旧时难觅i 2021-01-31 23:38

I want to show a UIPickerView on becoming FirstResponder of a UITextfield not the keyboard and fill the value in text field form the picker view.

any one knows this?

5条回答
  •  时光说笑
    2021-01-31 23:53

    Edit: this answer was correct at the time of writing. Apple has since introduced inputView. Mafonya answer is what you should be doing nowadays.

    It is possible to prevent the keyboard from popping up. Set your class to be the delegate of the UITextField: textField.delegate = self and add: after your interface declaration (before the {) in the header file.

    Now implement textFieldShouldBeginEditing::

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        // Show UIPickerView
    
        return NO;
    }
    

    If you want to be able to hide your pickerView this method won't work. What you could do then is create subclass of UITextField and override the *trackingWithTouch:event: selectors and do your magic in those. You probably still need to return NO from textFieldShouldBeginEditting: to prevent the keyboard from showing.

提交回复
热议问题