简体   繁体   中英

How to show my button when textfield clear button was pressed?

I check my textfield like this:

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

   return  YES;   
}

but it works only if I clear textfield by clear key, if I press clear button, it didn't work.

Implement the [UITextFieldDelegate textFieldShouldClear:] method as well:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM