gpt4 book ai didi

ios - 是否可以为数字键盘上的删除键添加目标方法?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:21 24 4
gpt4 key购买 nike

<分区>

我正在为我的 UITextField's 使用数字键盘.

我已经为我的文本字段设置了委托(delegate)。

我使用了所需的 delegate处理不同事件的方法。

但是当用户点击 x 时,我无法捕获事件 在数字键盘上标记 textfield hasBecomeFirstResponder textfield 中没有输入任何字符.

但是,当用户按下任何字符(或文本字段中至少有一个字符)然后按下删除键时,我可以获得删除事件。

我在 storyboard 中将键盘类型设置为数字键盘.

在 Storyboard和代码中都设置了委托(delegate)。

如果你想看一下,这里是代码:

 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

if ([string length]==0) {
NSLog(@"deleted");
return YES;
}

}

我认为只要我按下键盘上的任意键,上述方法就会被触发。但在我的例子中,当我在文本字段为空时按下删除键时,这个方法没有被命中。

我的问题是:我正在寻找一种以有效方式检测按下删除键的方法。我不想在删除按钮之上添加一个按钮。正如一个答案所建议的那样,向删除键添加一个按钮。

是否可以将目标方法添加到删除键,以便无论何时我按删除键,那个方法会被击中吗?(或者)当文本域中没有字符并且文本域已成为第一响应者时,是否有可能获得删除键事件?

I want to know because, I have four textfields placed in a horizontal stack view. When the user enters one character in first textfield, I am making the second text field as first responder,and the user enters the text on second textfield.

And the same way, I want to make the other textfield become first responder, when the user press delete key.Please note that, when I want to move back to other textfield by pressing the delete key, there will be no characters entered in the current textfield.And I am unable to detect delete key event when the textfield is empty.

enter image description here

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com