1

我有一个UITextField, 当按下 aUIPickerView来选择一个值。UIPickerView一旦选择了一个值,我如何获得解雇。另一个线程中的某个人告诉我到resignFirstResponder文本字段,但我的代码不起作用。有任何想法吗?注意:我有两个文本字段和 UI 选择器,这就是为什么我有 'if' 'else' 语句。

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.ageTextField)
    {
        [ageTextField resignFirstResponder];
        [agePickerView removeFromSuperview];
        return YES;
    }
    else
    {
        [relationshipTextField resignFirstResponder];
        [relationshipPickerView removeFromSuperview];
        return YES;
    }
}
4

3 回答 3

0

试试下面的代码可能会解决你的问题。

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
 {
     if (textField == self.ageTextField) 
     {
         [ageTextField resignFirstResponder];
     } 
     else 
     {
         [relationshipTextField resignFirstResponder];
     }
     [pickerView removeFromSuperview];
     return YES; 
 }

或按照以下方法退出键盘UIPickerView

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
于 2012-12-18T05:40:43.400 回答
0

请尝试在 UIPickerViewDelegate 方法中退出 UITextField,如下所示。

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    [self.ageTextField resignFirstResponder];
    pickerView.hidden = YES; //Show the pickerview again when you neeed it
}
于 2012-12-18T05:41:33.690 回答
0

实现 UIPickerViewDelegate 协议,实现如下方法:

- (void) pickerView: (UIPickerView*) pickerView
       didSelectRow: (NSInteger)     row
        inComponent: (NSInteger)     component
{
  [self.ageTextField resignFirstResponder];
}
于 2012-12-18T05:43:29.437 回答