Reputation: 75
I have googled as much as I can to try to find this. I am new to app development and programming in general. I want to have a view return to the previous view via swipe gesture.
Here is my ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var changeView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view .addGestureRecognizer(recognizer)
func swipeDown(recognizer : UISwipeGestureRecognizer) {
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Now with that there I am also a beginner with the new Xcode. If i remember correctly gestures used to be like buttons with a simple control-drag to the view and it would work.
In xcode I have my view that I want to swipe and I have the main view. What am I doing wrong?
error I receive now. Right now my AppDelegate.swift has not been touched. I believe that is where my selector goes, but I am unsure and I couldn't find much about this particular stuff.
[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance 0x7fe94bc7a080 2015-03-05 23:10:15.637 Swipe't[32779:3391684] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance
Upvotes: 0
Views: 2267
Reputation: 1135
1) Your swipeDown
function is inside viewDidLoad
. Shouldn't that be outside the viewDidLoad braces?
EDIT(Adding Modified Code)
override func viewDidLoad()
{
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view.addGestureRecognizer(recognizer)
}
func swipeDown(recognizer : UISwipeGestureRecognizer)
{
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
2) Secondly, though I am not sure about your use case,from information you have provided, I think you can utilize UIPageViewController. No need to implement swiping behavior yourself.
Upvotes: 1