2017-03-22 12 views
0

私はスウィフトにこの行を書き換えるしようとしている3 スウィフト2: ましょうlongPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(ターゲット:自己、アクション: "longPressDetected")ジェスチャー投げ認識されないセレクターエラー

スウィフト3 :

let longPress: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressDetected"))) 

が、それは、このエラーに

unrecognized selector sent to instance 
を投げているように見えます

呼び出すようにしようとしているされた機能はこれです:

func longPressDetected(_ sender: Any){} 
+0

(target:self、action:#selector(ViewController.handleLongPress(_ :))) –

答えて

1

スウィフト3で

func longPressDetected(_ sender: Any){} 

ため、対応するセレクタが

#selector(longPressDetected(_:)) 

あるいは単に

#selector(longPressDetected) 
です

余談:

func longPressDetected(_ sender: UILongPressGestureRecognizer){} 

をコンパイラが推測できる型に注釈を付けていない:送信者が特殊タイプなので、あなたはこれを指定する必要があります。

関連する問題