我删除了@UIApplicationMain
中的AppDelegate.swift
并编写了main.swift
,如下所示,但该程序仍然无法触发keyPressed
功能。但是每个keydown执行print("send event2")
。
如何解雇keyPressed
功能?这个程序有问题吗?
import UIKit
import Foundation
class TApplication: UIApplication {
override func sendEvent(_ event: UIEvent!) {
super.sendEvent(event)
}
override var keyCommands: [UIKeyCommand]? {
print("send event2") // this is an example
return [
UIKeyCommand(input: "1", modifierFlags: [], action: Selector(("keyPressed:")), discoverabilityTitle: “1”),
UIKeyCommand(input: "2", modifierFlags: .shift, action: Selector("keyPressed:"), discoverabilityTitle: “2”)]
]
}
func keyPressed(sender: UIKeyCommand) {
print("keypressed event !!!!!!!!") // this is an example
}
}
答案 0 :(得分:0)
我将'selector'修改为#selector(swift 3)并最终解决了问题,也许有一个bug