Ich habe zwei Etiketten, Label1 und Label2. Ich möchte eine einzelne Funktion erstellen, die ausgibt, welche Beschriftung angezapft wird, indem ich UITTapRecognizer für beide Beschriftungen erzeuge, die dieselbe Funktion mit selector aufrufen, der ein Argument übergibt. Unten ist der lange Weg, es zu tun, der chaotisch ist aber funktioniert. Wenn ich weiß, wie man ein Argument (Int) in den Selektor eingibt, wäre es viel sauberer.Pass extra Argument für UItapgestureRecognizer mit Selektor
let topCommentLbl1Tap = UITapGestureRecognizer(target: self, action: #selector(DiscoverCell().doubleTapTopComment1))
topCommentLbl1Tap.numberOfTapsRequired = 2
topCommentLbl1.userInteractionEnabled = true
topCommentLbl1.addGestureRecognizer(topCommentLbl1Tap)
let topCommentLbl2Tap = UITapGestureRecognizer(target: self, action: #selector(DiscoverCell().doubleTapTopComment2))
topCommentLbl2Tap.numberOfTapsRequired = 2
topCommentLbl2.userInteractionEnabled = true
topCommentLbl2.addGestureRecognizer(topCommentLbl2Tap)
func doubleTapTopComment1() {
print("Double Tapped Top Comment 1")
}
func doubleTapTopComment2() {
print("Double Tapped Top Comment 2")
}
Gibt es eine Möglichkeit die Auswahlverfahren so zu modifizieren, dass ich so etwas wie
func doubleTapTopComment(label:Int) {
if label == 1 {
print("label \(label) double tapped")
}