benpete420 benpete420 - 29 days ago 19
iOS Question

Swipe gesture recognizer swift

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"
}

}





}

Answer

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:"))