UITextField and UIPickerView

Is it possible for a UIPickerView to appear instead of a keyboard when selecting a UITextField? Each option in Interface Builder is a kind of keyboard.

I suppose I could create a UIPickerView programmatically and create it when the UITextField senses the touchUpInside event and then tells the UITextField to resignFirstResponder, but that seems a bit hacky.

Is there an β€œofficial” or more β€œright” way to do this?

Thank!

+3
source share
1 answer

You can implement this code and override the default behavior (i.e. showing the keyboard):

#pragma mark -
#pragma mark UITextFieldDelegate methods

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                                                    message:@"Bouh!"
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    return NO;
}

, UIAlertView, UIPickerView .

+6

Source: https://habr.com/ru/post/1727148/


All Articles