按下文本字段清除按钮时如何显示我的按钮?

时间:2012-07-27 10:52:10

标签: ios xcode textfield clear

我像这样查看我的文本域:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([subtitleField.text length] == 0)
    {
        searchAddress.hidden = NO;
    }
    else 
    {
        searchAddress.hidden = YES;
    }

   return  YES;   
}

但只有当我通过清除键清除文本字段时它才有效,如果我按下清除按钮,它就不起作用。

1 个答案:

答案 0 :(得分:4)

同样实施[UITextFieldDelegate textFieldShouldClear:]方法:

- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    searchAddress.hidden = NO;
    return YES;
}