xcode创建了一些警告,因为我更新到7.3.1:“没有用Objective-C选择器声明的方法('nextPage')”。我不确定我现在需要做什么。这两行产生警告:
let leftSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))
let rightSwipe = UISwipeGestureRecognizer (target: self, action: Selector("nextPage"))
这是整个VC代码:
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)
}
}
}
我在研究时发现了这个:
选择器(“funcName”)已更改为#selector(ClassName.funcName)
我想“funcName”将是nextPage,但我必须将其设置为ClassName?
不幸的是,xcode没有提供任何解决此问题的建议。希望你能帮忙。感谢。
答案 0 :(得分:3)
您需要nextPage
viewDidLoad()
,然后#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))
}