gpt4 book ai didi

ios - 滑动手势给出 NSException

转载 作者:行者123 更新时间:2023-11-28 15:49:56 25 4
gpt4 key购买 nike

我是 swift 编程的新手。所以我试图将滑动手势添加到我的 iOS 应用程序中。但是当我尝试滑动时,它会停止应用程序并说 NSException 被捕获。这是我写的代码。

override func viewDidLoad() {
super.viewDidLoad()

textLabels.append(label0)
textLabels.append(label1)
textLabels.append(label2)
textLabels.append(label3)
textLabels.append(label4)
textLabels.append(label5)
textLabels.append(label6)
textLabels.append(label7)
textLabels.append(label8)
textLabels.append(label9)
textLabels.append(label10)
textLabels.append(label11)
textLabels.append(label12)
textLabels.append(label13)
textLabels.append(label14)
textLabels.append(label15)

setupInitial()
print(textLabels.count)
var request = GADRequest()
request.testDevices = [kGADSimulatorID]
bannerView.adUnitID = "ca-app-pub-8950283126375215/1694851281"
bannerView.rootViewController = self
bannerView.load(request)
createAndLoadInterstitial()


let swipeRight = UISwipeGestureRecognizer(target: self, action: Selector(("gesture:")))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)

let swipeDown = UISwipeGestureRecognizer(target: self, action: Selector(("gesture:")))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeDown)
//setView(view: hideView, hidden: false)

}

func gesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
print("Swiped right")
case UISwipeGestureRecognizerDirection.down:
print("Swiped down")
case UISwipeGestureRecognizerDirection.left:
print("Swiped left")
case UISwipeGestureRecognizerDirection.up:
print("Swiped up")
default:
break
}
}
}

我也尝试像这样将 UIGestureRecognizerDelegate 添加到我的 viewController 类中

class ViewController: UIViewController, UIGestureRecognizerDelegate

但是没有用。我还添加了 UIGestureRecognizer。请帮助我,我真的被困在这里了。我正在使用 Xcode 8 和 OSX El Capitan。提前致谢。

最佳答案

新的 #selector() 已弃用字符串类型的 Selector()

将您的操作更新为#selector(gesture(gesture:)),这样应该可以解决问题

let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(gesture(gesture:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)

关于ios - 滑动手势给出 NSException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42446324/

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