Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Swift Programming
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 27th, 2015, 07:31 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 05:44 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.