2016-12-17 2 views
0

AppDelegate.swift@UIApplicationMainを削除し、以下のようにmain.swiftを書きましたが、プログラムはまだkeyPressedの機能を起動できません。しかし、keydown毎にprint("send event2")を実行します。すばらしいiOSアプリのキーイベントをインターセプトする方法はありますか?

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

私は#selector(SWIFT 3)であることを 'セレクタ' を修正し、最終的に問題を解決し、多分バグ

+0

"アクション:#selector(keyPressed(差出人:))" があったの代わりに "アクション:セレクタ(( "keyPressed:")) " – baileymiller2017

関連する問題