UITextField 和 UIPickerView

发布于 2024-08-16 20:15:47 字数 264 浏览 4 评论 0原文

当选择 UITextField 时,是否可以显示 UIPickerView 而不是键盘? Interface Builder 中的每个选项都是某种键盘。

我想我可以以编程方式创建一个 UIPickerView 并在 UITextField 注册 touchUpInside 事件时创建一个 UIPickerView,然后告诉 UITextField resignFirstResponder,但这似乎有点黑客。

有没有“官方”或更“正确”的方法来做到这一点?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2024-08-23 20:15:47

您可以实现此代码并覆盖默认行为(即显示键盘):

#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;
}

您不妨显示自己的 UIPickerView 并执行您的操作,而不是显示 UIAlertView。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文