gpt4 book ai didi

ios - 没有使用 Objective-C 选择器 ('nextPage' 声明的方法)

转载 作者:搜寻专家 更新时间:2023-11-01 06:38:34 25 4
gpt4 key购买 nike

自从我更新到 7.3.1 后,xcode 创建了一些警告:“没有使用 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)

}

}

}

我在研究的时候发现了这个:

Selector("funcName") 更改为#selector(ClassName.funcName)

我想“funcName”应该是 nextPage,但我必须将什么设置为 ClassName?

不幸的是,xcode 没有提供任何解决此问题的建议。希望你能帮忙。谢谢。

最佳答案

您需要将 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))
}

关于ios - 没有使用 Objective-C 选择器 ('nextPage' 声明的方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com