gpt4 book ai didi

ios - 确定响应者链是否将处理一个 Action

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

The responder chain is cool .

特别是,能够将自定义操作发送给第一响应者,该响应者将冒泡给可能感兴趣的任何其他人:[[UIApplication sharedApplication] sendAction: @selector(commandToSend) to: nil from: self forEvent:无].

或更少的自定义操作:

[[UIApplication sharedApplication] sendAction: @selector(resignFirstResponder) to: nil from: self forEvent: nil]

我想知道 – 是否有办法预先测试来自特定发件人的特定操作是否会被处理如果现在发送?一个明显的用途是启用和禁用发送操作的按钮,具体取决于当前是否要处理该操作。

如果你碰巧认识第一响应者,我想你可以做 [aResponder targetForAction: @selector(methodYouWantToSend) withSender: selfOrSomethingElse],然后检查答案是否为 nil。但是似乎没有与 UIApplicationsendAction:... 等效的方法,它会自动从第一响应者开始并运行。

最佳答案

有一个 delightful solution here通过利用响应者链找到第一响应者。

一旦您知道第一响应者,就很容易询问当前响应者链是否处理特定操作。如果您愿意,您甚至可以查明谁将处理它。

const SEL action = @selector(theActionYouWantToSend);
UIResponder *const currentTarget = [[UIResponder firstResponder] targetForAction: action withSender: self];
const bool actionIsHandled = currentTarget != nil;

关于ios - 确定响应者链是否将处理一个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27863940/

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