2

私は UITextField インスタンスを持っていますsecureTextEntry = YES。フィールドが最初にフォーカスされると、キーを押すとフィールドがクリアされます。これは、iOS の標準的な動作のようです。

私が知る限り、UIControlEventEditingChangedトリガーされません。購読も試みましUIControlEventAllEditingEventsたが、トリガーされていないようです。enabledUIButtonの属性を設定するためにフィールドがいつ編集されたかを知ることに依存しているため、これは私にとって問題を引き起こしています。

このようにフィールドがクリアされたときに発生するイベントはありますか?

私の問題に関する彼らのコンテキストは、このGitHubの問題で見ることができます。

4

3 に答える 3

1

UITextField のデリゲートを使用できます。

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:text];
    [self performSelector:@selector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    [self performSelector:@selector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (void) updateButton {
    someButton.enabled = NO;
}
于 2013-09-04T02:32:06.073 に答える
0

のアクションを追加するUIControlEventAllEventsと、テキスト フィールドがこのようにクリアされたときにメソッドが呼び出されず、イベントがトリガーされないことが確認されます。

于 2013-09-04T03:02:35.577 に答える
0

こんにちは、次のメソッドを使用できます。

 - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        [self performSelector:@selector(MakeButtonEnabled:) withObject:nil afterDelay:0.2];
        return YES;
    }

- (void) MakeButtonEnabled:(id)sender {
    UIButton *yourButton=(UIBUtton*) sender;
    yourBUtton.enabled = NO;
}

これがあなたを助けることを願っています。

于 2013-09-04T03:50:37.607 に答える