1

我像这样检查我的文本字段:

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

   return  YES;   
}

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

4

1 回答 1

4

也实现该[UITextFieldDelegate textFieldShouldClear:]方法:

- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    searchAddress.hidden = NO;
    return YES;
}
于 2012-07-27T10:56:09.247 回答