简体   繁体   English

UITextField和UIPickerView

[英]UITextField and UIPickerView

Is it possible for a UIPickerView to appear instead of a keyboard when a UITextField is selected? 当选择UITextField时,是否可以显示UIPickerView而不是键盘? Every option in Interface Builder is some sort of keyboard. Interface Builder中的每个选项都是某种键盘。

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. 我想我可以以编程方式创建一个UIPickerView并在UITextField注册一个touchUpInside事件时创建一个,然后告诉UITextField resignFirstResponder,但这看起来有点像黑客攻击。

Is there an "official" or more "correct" way to do this? 是否有“官方”或更“正确”的方式来做到这一点?

Thanks! 谢谢!

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. 您可以展示自己的UIPickerView并做自己的事情,而不是显示UIAlertView。

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

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