gpt4 book ai didi

ios - swift3 中的选择器

转载 作者:IT王子 更新时间:2023-10-29 07:37:29 24 4
gpt4 key购买 nike

为什么这在 swift 3 中不起作用?它在运行时崩溃说:

'-[my_app_name.displayOtherAppsCtrl tap:]: unrecognized selector sent to instance 0x17eceb70'

    override func viewDidLoad() {
super.viewDidLoad()

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Register cell classes
//self.collectionView!.register(ImageCell.self, forCellWithReuseIdentifier: reuseIdentifier)

// Do any additional setup after loading the view.

let lpgr = UITapGestureRecognizer(target: self, action: Selector("tap:"))
lpgr.delegate = self
collectionView?.addGestureRecognizer(lpgr)
}

func tap(gestureReconizer: UITapGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.ended {
return
}

let p = gestureReconizer.location(in: self.collectionView)
let indexPath = self.collectionView?.indexPathForItem(at: p)

if let index = indexPath {
//var cell = self.collectionView?.cellForItem(at: index)
// do stuff with your cell, for example print the indexPath
print(index.row)
} else {
print("Could not find index path")
}
}

最佳答案

Selector("tap:") 现在应该写成 #selector(tap(gestureReconizer:))

此外,您应该根据新的 Swift API Guidelines 将 tap 声明为 func tap(_ gestureRecognizer: UITapGestureRecognizer)在这种情况下,您的选择器将变为 #selector(tap(_:))

关于ios - swift3 中的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38038418/

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