本文介绍了如何关闭连接到 UITextField 的 UIPicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UITextField
,当推送一个 UIPickerView
时会出现来选择一个值.选择一个值后,如何让 UIPickerView
关闭.另一个线程中的某人告诉我 resignFirstResponder
文本字段,但我的代码不起作用.有任何想法吗?注意:我有两个文本字段和 UI 选择器,这就是为什么我有if"else"语句的原因.
I have a UITextField
, and when pushed a UIPickerView
comes up to choose a value. How do I get the UIPickerView
to dismiss once a value is chosen. Someone in another thread told me to resignFirstResponder
the textfield, but my code isn't working. Any ideas? NOTE: I have two text fields and UI Pickers, that's why I have the 'if' 'else' statement.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.ageTextField)
{
[ageTextField resignFirstResponder];
[agePickerView removeFromSuperview];
return YES;
}
else
{
[relationshipTextField resignFirstResponder];
[relationshipPickerView removeFromSuperview];
return YES;
}
}
推荐答案
实现 UIPickerViewDelegate 协议并实现如下方法:
Implement the UIPickerViewDelegate protocol and implement the following method:
- (void) pickerView: (UIPickerView*) pickerView
didSelectRow: (NSInteger) row
inComponent: (NSInteger) component
{
[self.ageTextField resignFirstResponder];
}
这篇关于如何关闭连接到 UITextField 的 UIPicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!