【问题标题】:How to make UIAlertView call `alertViewShouldEnableFirstOtherButton:` after making changes?进行更改后如何使 UIAlertView 调用 `alertViewShouldEnableFirstOtherButton:`?
【发布时间】:2013-04-15 08:12:37
【问题描述】:

我有一个带有 UITextField 的 UIAlertView。我已连接 UIAlertView 委托,并根据 UITextField 中的文本在 alertViewShouldEnableFirstOtherButton: 中返回“是”或“否”。

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

不幸的是,我不知道如何让 UIAlertView 调用 alertViewShouldEnableFirstOtherButton: 委托方法,以便在我更改 textField 的文本后启用或禁用另一个按钮。

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


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

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


有没有一种干净的方法可以让警报视图调用alertViewShouldEnableFirstOtherButton:

【问题讨论】:

    标签: ios cocoa-touch uialertview


    【解决方案1】:

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

    这将起作用:

    [textField sendActionsForControlEvents:UIControlEventEditingChanged];
    

    【讨论】:

    • 我也遇到了这个问题,这个答案有效,似乎是正确的做法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 2011-01-02
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多