John Frankes
John Frankes

Reputation: 333

UITextField and UIPickerView

Is it possible for a UIPickerView to appear instead of a keyboard when a UITextField is selected? Every option in Interface Builder is some sort of keyboard.

I suppose I could create a UIPickerView programmatically and create one when the UITextField registers a touchUpInside event, then tell the UITextField to resignFirstResponder, but that seems a bit of a hack.

Is there an "official" or more "correct" way to do this?

Thanks!

Upvotes: 3

Views: 3449

Answers (1)

Adrian Kosmaczewski
Adrian Kosmaczewski

Reputation: 7956

You can implement this code and override the default behaviour (that is, 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;
}

Instead of showing a UIAlertView, you might as well show your own UIPickerView and do your thing.

Upvotes: 6

Related Questions