我删除了@UIApplicationMain中的AppDelegate.swift,并按下面的方式编写了main.swift,但是程序仍然不能触发keyPressed函数。但是每次按键都要执行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
}
}发布于 2016-12-18 01:17:53
我将“选择器”修改为#选择器,并最终解决了问题,可能是个错误。
https://stackoverflow.com/questions/41197180
复制相似问题