0

I have been looking on the internet for a few hours now on how to use the Swipe Gesture Recognizer. I do not want to code it, because I have tried nearly every single example and that doesn't work. However, I know that there is a Swipe Gesture Recognizer in the object library, but it doesn't seem to work. Can somebody please show me a link to a place where I can use the Swipe Gesture Recognizer from the Object Library or show me how to do it?

Thanks,

Ben

(If I am being to broad for some reason, or you don't like my question, please do not -1 this, just comment and I will make the change, please).

Crash Log: 2016-01-09 10:59:33.392 Capitals[250:14059] -[Capitals.Alabama1 handleSwipes]: unrecognized selector sent to instance 0x14f695150 2016-01-09 10:59:33.397 Capitals[250:14059] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Capitals.Alabama1 handleSwipes]: unrecognized selector sent to instance 0x14f695150' * First throw call stack: (0x184bdcf48 0x19984ff80 0x184be3c5c 0x184be0c00 0x184ae4cac 0x18a6eb330 0x18a314b5c 0x18a1a285c 0x18a6ec70c 0x18a1618b8 0x18a15e63c 0x18a1a06cc 0x18a19fcc8 0x18a1704a4 0x18a16e76c 0x184b94544 0x184b93fd8 0x184b91cd8 0x184ac0ca0 0x18fb40088 0x18a1d8ffc 0x10008a264 0x19a0928b8) libc++abi.dylib: terminating with uncaught exception of type NSException

(Handle Swipes is the name of the function)

Here is the code:

import UIKit

class Alabama1: UIViewController { @IBOutlet weak var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))
    let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))

    // Do any additional setup after loading the view, typically from a nib.
    reveal.direction = .Up
    next.direction = .Left

    view.addGestureRecognizer(reveal)
    view.addGestureRecognizer(next)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func handleSwipes(sender:UISwipeGestureRecognizer) {
    if (sender.direction == .Up) {
        label.text = "Motgomery"
    }

}





}
7
  • You said, you tried something and it doesn't work. Can you include the code that you used ?
    – Midhun MP
    Commented Jan 9, 2016 at 16:27
  • Could I include the tutorial I copied it from? Here it is: youtube.com/watch?v=9r1UFNeVuFA . I changed the "var" to "let" to work with the latest version of swift. @MidhunMP
    – benpete420
    Commented Jan 9, 2016 at 16:33
  • So what not worked ? Did you followed all those steps mentioned in the tutorial ?
    – Midhun MP
    Commented Jan 9, 2016 at 16:40
  • @MidhunMP I followed all of the steps in the tutorial, and when I tried it out, it crashed at the function part. I double checked the function, but it was exactly the same as the video. I checked the function because according to xcode, my app crashed there.
    – benpete420
    Commented Jan 9, 2016 at 16:43
  • Please include the code that you are using for adding swipe gesture and the selector method. Include the crash log you got
    – Midhun MP
    Commented Jan 9, 2016 at 16:56

2 Answers 2

3

You are missing semicolumn in adding event. Try like so:

let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
1
  • @NickCatlib Thank you so much !
    – benpete420
    Commented Jan 9, 2016 at 17:14
1

in swift3 Version :

   let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(MainMenuViewController.handleSwipes(_sender:)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.