选择 UITextField 时,是否可以出现 UIPickerView 而不是键盘?Interface Builder 中的每个选项都是某种键盘。
我想我可以以编程方式创建一个 UIPickerView 并在 UITextField 注册一个 touchUpInside 事件时创建一个,然后告诉 UITextField resignFirstResponder,但这似乎有点 hack。
是否有“官方”或更“正确”的方式来做到这一点?
谢谢!
选择 UITextField 时,是否可以出现 UIPickerView 而不是键盘?Interface Builder 中的每个选项都是某种键盘。
我想我可以以编程方式创建一个 UIPickerView 并在 UITextField 注册一个 touchUpInside 事件时创建一个,然后告诉 UITextField resignFirstResponder,但这似乎有点 hack。
是否有“官方”或更“正确”的方式来做到这一点?
谢谢!
您可以实现此代码并覆盖默认行为(即显示键盘):
#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 并做自己的事情。