Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Swift Programming
BOOK: Beginning Swift Programming
This is the forum to discuss the Wrox book Beginning Swift Programming by Wei-Meng Lee; ISBN: 978-1-119-00931-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Swift Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 27th, 2015, 07:31 AM
Authorized User
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default SwipeGestureRecognizer not working properly for left, up, and down

I'm trying to implement swipeGestureRecognizer for all four directions in a swift app, on a bunch of dynamically generated UIViews. So basically, I want each of these views to respond to swipes in all four directions. Here is my code

    import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

    //create a view to represent the main box
    let mainBox = UIView(frame: CGRectMake(0,0, 320, 40 ))
        mainBox.backgroundColor = UIColor.redColor()
        mainBox.layer.cornerRadius = 0
        self.view.addSubview(mainBox) //Add the newly created view to the main view(self)

    //Create some UIViews on the fly

    for var i=0; i<8; ++i{
        //Add an image view
        let tile = UIImageView(frame: CGRectMake(CGFloat(i)*CGFloat(40),0,40,40 )) //Create a new view
        //Style the imageview

        tile.userInteractionEnabled = true

        let swipeRight = UISwipeGestureRecognizer(target: self, action:Selector("tileRightSwiped:"))
        swipeRight.direction = .Right

        let swipeLeft = UISwipeGestureRecognizer(target: self, action: Selector("tileLeftSwiped"))
        swipeLeft.direction = .Left

        let swipeDown = UISwipeGestureRecognizer(target: self, action: Selector("tileDownSwiped"))
        swipeDown.direction = .Down

        let swipeUp = UISwipeGestureRecognizer(target: self, action: Selector("tileUpSwiped"))
        swipeUp.direction = .Up

        mainBox.addSubview(tile) //Add the newly created view to mainBox



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

//swipe gestures
func tileRightSwiped(gestureRecognizer: UISwipeGestureRecognizer){
    print("right swiped")

func tileLeftSwiped(gestureRecognizer: UISwipeGestureRecognizer){
    print("left swiped ")

func tileDownSwiped(gestureRecognizer: UISwipeGestureRecognizer){
    print("down swiped ")

func tileUpSwiped(gestureRecognizer: UISwipeGestureRecognizer){
    print("Up swiped ")


Right swipe works just fine but I can't understand why for the other 3 directions, the app aborts unexpectedly and I get an error like this
"[myApp.ViewController tileDownSwiped]: unrecognized selector sent to instance 0x7fd230dbf5d0" Am I incorrectly using the swipegesture recognizer or is something wrong somewhere else in my code?
I'm at a total loss. Any help greatly appreciated.

Similar Threads
Thread Thread Starter Forum Replies Last Post
ch 8 code is not working properly Dev_gh78 C# 1 August 4th, 2006 12:16 AM
Scheduled VBS file is not working properly bsrini SQL Server 2000 16 April 14th, 2004 04:09 AM
PreparedStatement not working properly wslyhbb Java Databases 3 September 9th, 2003 01:08 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.