如何在uitextfield中隐藏UIPickerView?

时间:2015-06-23 17:22:15

标签: ios objective-c uipickerview

我创建了一个UITextField,并将此inputview设置为pickerview。如果我点击文本字段,则会显示选择器视图,但如果我不想更改选择器视图值,我会尝试单击视图以关闭选择器视图,但它无效... 我在viewDidLoad()中设置了textfield inputview:

picker = [[UIPickerView alloc] init];
picker.dataSource = self;
picker.delegate = self;
self.pickerTF.inputView = picker;

pickerTF是UITextfield,选择器是UIPickerView。

我尝试使用这些方法来解雇pickerview:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return true;
}
-(BOOL)disablesAutomaticKeyboardDismissal{
return NO;
}

我已经编辑过.h文件:

@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, NetworkManagerDelegate, UITextFieldDelegate>

1 个答案:

答案 0 :(得分:1)

在文本字段的超级视图中添加一个点击手势识别器,并在超级视图上调用endEditing: