gpt4 book ai didi

ios - 更改后如何使 UIAlertView 调用 `alertViewShouldEnableFirstOtherButton:`?

转载 作者:可可西里 更新时间:2023-11-01 03:30:07 26 4
gpt4 key购买 nike

我有一个带有 UITextField 的 UIAlertView。我已连接 UIAlertView 委托(delegate),并根据 UITextField 中的文本在 alertViewShouldEnableFirstOtherButton: 中返回 YES 或 NO。

我需要以编程方式更改 textField 的文本。这按预期工作。

不幸的是,我不知道如何让 UIAlertView 调用 alertViewShouldEnableFirstOtherButton: 委托(delegate)方法,以便它在我更改文本字段的文本后启用或禁用其他按钮。

我认为 UIAlertView 注册为 UITextField 的目标,所以我尝试从 textField 发送 UIControlEventValueChanged。没用。


从堆栈跟踪中我发现委托(delegate)方法是从私有(private) UIAlertView 方法 _alertSheetTextFieldDidChange: 调用的。

因此,如果我在更改文本后执行 [self.currentAlert performSelector:@selector(_alertSheetTextFieldDidChange:) withObject:textField];,委托(delegate)方法将被调用,按钮的启用状态也会更改。但是,由于这是一个私有(private)方法,该应用程序可能会被拒绝。我不想冒险。


是否有一种干净的方法来使警报 View 调用 alertViewShouldEnableFirstOtherButton:

最佳答案

我在发送控制事件方面走在了正确的轨道上。我只是选择了错误的事件。

这会起作用:

[textField sendActionsForControlEvents:UIControlEventEditingChanged];

关于ios - 更改后如何使 UIAlertView 调用 `alertViewShouldEnableFirstOtherButton:`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16146892/

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