OGeek|极客世界-中国程序员成长平台

标题: iphone - UITextField ResignFirstRespond 在 iphone 中不起作用? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:56
标题: iphone - UITextField ResignFirstRespond 在 iphone 中不起作用?

我设计了一个带有四个 UITextField 的表单。第一个用于输入数字,第二个用于输入姓名,第三个用于选择日期,最后一个用于选择时间。第一个使用数字键盘的文本字段将通过使用键盘上的完成按钮隐藏。如果用户从第一个(数字文本字段)输入第二个(名称文本字段)时,第一个键盘将完美隐藏。如果用户输入名称并选择日期文本字段在操作表中显示日期选择器,则当用户选择日期并点击完成/取消按钮时,我隐藏操作表。但是,名称文本字段键盘不会从屏幕上消失。我绑定(bind)了下面的代码,它不起作用。任何人都可以提出这个澄清的想法吗?提前致谢。

-(void)textFieldDidBeginEditingUITextField *)textField
{
    if (textField == numberTextfield) 
    {
        [textField setInputAccessoryView:keyboardToolbar]; 

    }
    else if(textField == nameTextfield)
    {

    }
    else if(textField == dateTextField)
    {
        [self showdateActionSheet];

        [nameTextfield resignFirstResponder];
        [dateTextField resignFirstResponder];
    }
    else if(textField == timeTextField)
    {         
        [timeTextField resignFirstResponder];
        [nameTextfield resignFirstResponder];
    }
} 

- (BOOL) textFieldShouldReturnUITextField *)textField  // If the user select Return key it is dismissing fine
{ 
    [nameTextfield resignFirstResponder];

    return YES;
}

-(BOOL) textFieldShouldEndEditingUITextField *)textField
{
    [nameTextfield resignFirstResponder];
    return YES;
}

-(void) DateDone
{
   [nameTextfield resignFirstResponder];
}

-(void) timeDone
{
   [nameTextfield resignFirstResponder];
}



Best Answer-推荐答案


戈皮纳特。请尝试我的以下代码,

- (BOOL)textFieldShouldBeginEditingUITextField *)textField 
{ 
    if (textField == dateTextField )
    {  
        [nameTextfield resignFirstResponder]; 

        [self showdateActionSheet];

        [dateTextField resignFirstResponder];
    }
    else if( textField == timeTextField)
    {
        [nameTextfield resignFirstResponder];
        [self ShowTime];
        [timeTextField resignFirstResponder];
    }
    return YES; 
}

我相信我会帮助你的。

关于iphone - UITextField ResignFirstRespond 在 iphone 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9512450/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4