mojomo mojomo - 1 year ago 105
Swift Question

No method declared with Objective-C selector ('nextPage')

xcode creates some warnings since I updated to 7.3.1: "No method declared with Objective-C selector ('nextPage')". I'm not sure what I need to do now. These are the two lines that produce the warning:

let leftSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))
let rightSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))


This is the entire VC code:

import Foundation
import UIKit
class VC1 : UIViewController {

class MyCustomNavigationController: UINavigationController {

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

return (visibleViewController?.supportedInterfaceOrientations())!

}


override func shouldAutorotate() -> Bool {

return (visibleViewController?.shouldAutorotate())!

}

}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

return UIInterfaceOrientationMask.Portrait

}

override func shouldAutorotate() -> Bool {

return true

}

override func viewDidLoad() {

super.viewDidLoad()

func nextPage(sender:UISwipeGestureRecognizer) {

switch sender.direction {



case UISwipeGestureRecognizerDirection.Left:

print("SWIPED LEFT", terminator: "")

self.performSegueWithIdentifier("seg1", sender: nil)

default:

break

}


let leftSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))

let rightSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))


leftSwipe.direction = .Left

rightSwipe.direction = .Right



view.addGestureRecognizer(leftSwipe)

view.addGestureRecognizer(rightSwipe)

}

}

}


I found this when researching:

Selector("funcName") was changed to #selector(ClassName.funcName)

I imagine that "funcName" would be nextPage, but what do I have to set as ClassName?

Unfortunately, xcode doesn't provide any suggestions to fix this. Hope you can help. Thanks.

Answer Source

You need to put nextPage out of viewDidLoad() and then #selector(VC1.nextPage)

func nextPage(sender:UISwipeGestureRecognizer) {

    switch sender.direction {



    case UISwipeGestureRecognizerDirection.Left:

        print("SWIPED LEFT", terminator: "")

        self.performSegueWithIdentifier("seg1", sender: nil)

    default:

        break

    }

override func viewDidLoad() {

   super.viewDidLoad()

   let leftSwipe = UISwipeGestureRecognizer (target: self, action:  #selector(VC1.nextPage))

   let rightSwipe = UISwipeGestureRecognizer (target: self, action:  #selector(VC1.nextPage))
}