UIAccessibilityCustomAction

UIAccessibilityCustomAction

当前在触发我的UIAccessibilityCustomAction选择器中的方法时遇到问题。以下代码位于自定义UITableViewCell类中,并在单元格初始化时调用。它可以正确显示UIAccessibilityCustomAction,但是我无法在设备和辅助功能检查器上都执行操作。我究竟做错了什么?

@objc func doSomething() {
    print("something")
}

func addAccessibilityActions() {
    accessibilityCustomActions = [
        UIAccessibilityCustomAction(name: NSLocalizedString("information", comment: ""), target: self, selector: #selector(doSomething))
    ]
}

最佳答案

我究竟做错了什么?


您的custom actionUIAccessibilityCustomAction数组中定义良好,但我认为您的实现不正确以执行该操作。尝试以下代码片段:

@objc func doSomething() -> Bool {

    //Code to be implemented for the appropriate action.
    print("something")

    return true
}


此外,从iOS 13开始,您可以使用new syntax进行自定义操作,以引入如下所示的闭包:

accessibilityCustomActions = [
    UIAccessibilityCustomAction(name: NSLocalizedString("information", comment: ""),
                                actionHandler: {(customAction: UIAccessibilityCustomAction) -> Bool in
                                                print("something")
                                                return true})]

关于ios - UIAccessibilityCustomAction选择器未触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57994864/

10-11 15:48