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

标题: ios - 清除带有secureTextEntry = YES 的UITextField 时是否触发事件? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:07
标题: ios - 清除带有secureTextEntry = YES 的UITextField 时是否触发事件?

我有一个 secureTextEntry = YES 的 UITextField 实例。当该字段首次获得焦点时,任何按键都会清除该字段,这似乎是 iOS 上的标准行为。

据我所知,UIControlEventEditingChanged 没有被触发。我也尝试订阅 UIControlEventAllEditingEvents 但它似乎没有被触发。这给我带来了一个问题,因为我依赖于知道何时编辑该字段来设置 UIButton 的 enabled 属性。

以这种方式清除字段时是否会触发事件?

可以在 GitHub issue 中看到他们围绕我的问题的上下文.



Best Answer-推荐答案


您可以使用 UITextField 的委托(delegate):

- (BOOL) textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)string {
    NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:text];
    [self performSelectorselector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (BOOL)textFieldShouldClearUITextField *)textField {
    [self performSelectorselector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (void) updateButton {
    someButton.enabled = NO;
}

关于ios - 清除带有secureTextEntry = YES 的UITextField 时是否触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18604488/






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