【发布时间】:2017-02-21 21:42:13
【问题描述】:
无论我做什么,我总是得到这个错误。
这是在我的cellForItemAtIndexPath 函数中:
cell.postCell.profileImage.userView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "pressedUserImage:"))
以及动作方法:
func pressedUserImage(userView: UIImageView) {
print(userView.superview) // error happens here.
当然,我的 userView 位于深层视图层次结构中,但它仍然必须工作。由于某种原因,它没有。即使我这样做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。
这是错误:
*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[project.PostspressedUserImage]:无法识别的选择器发送到实例 0x7a9a65e0”
【问题讨论】:
-
可以分享
cellForItemAtIndexPath函数吗? -
能否也显示确切的异常消息文本
-
手势识别器处理程序的参数是手势识别器,没有被触摸的视图。在发送者上使用 .view 来获取发送视图。
-
很抱歉,都在那里。
-
@vacawama,你是什么意思? UITapGestureRecognizer 是手势识别器,不是吗?
标签: ios uicollectionview uitapgesturerecognizer