gpt4 book ai didi

ios - swift 3 : unrecognized selector sent to instance for gesture recognizer

转载 作者:行者123 更新时间:2023-11-28 18:50:28 26 4
gpt4 key购买 nike

无论我做什么,我总是会遇到这个错误。

这是在我的 cellForItemAtIndexPath 函数中:

cell.postCell.profileImage.userView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "pressedUserImage:"))

和 Action 方法:

func pressedUserImage(userView: UIImageView) {
print(userView.superview) // error happens here.

当然,我的 userView 位于深层 View 层次结构中,但它仍然需要工作。出于某种原因,它没有。即使我执行 userImage.superview?.superview 等等,我仍然会收到错误消息。我尝试使用 #selector(pressedUserImage(_:) 代替,但没有运气。尝试过 Selector("pressedUserImage:")。没有。

我哪里出错了?

更新,这里是 cellForItemAtIndexPath 函数:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath) as! Posts
cell.postCell.profileImage.userView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "pressedUserImage:"))
cell.postCell.buttonView.sharePost.addTarget(self, action: #selector(pressedShareButton), for: .touchUpInside)

return cell
}

postCell 基本上是一个包含图像、名称和文本的 UIView

这是错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[project.Posts pressedUserImage]: unrecognized selector sent to instance 0x7a9a65e0'

最佳答案

看起来问题出在您的函数签名上。它需要接受手势识别器作为参数,而不是包含 View 。

喜欢:

func pressedUserImage(_ sender: UITapGestureRecognizer) { ... }

关于ios - swift 3 : unrecognized selector sent to instance for gesture recognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378555/

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