以编程方式添加视图和手势 - “发送到实例的无法识别的选择器”
Posted
技术标签:
【中文标题】以编程方式添加视图和手势 - “发送到实例的无法识别的选择器”【英文标题】:Programmatically adding a view and gesture - "unrecognized selector sent to instance" 【发布时间】:2016-09-24 21:52:48 【问题描述】:当我删除发件人时,我可以调用“handleTap”函数,但是当我重新添加sender: UIPanGestureRecognizer
时,我会收到此错误:unrecognized selector sent to instance
。我想不通!
class DrawingViewController: UIViewController, UIGestureRecognizerDelegate
var newlyAddedSticker = UIImage()
didSet
makeNewSticker()
func makeNewSticker()
let newSticker = UIImageView(image: newlyAddedSticker)
view.addSubview(newSticker)
let myPanGesture = UIPanGestureRecognizer(target: self, action: "handleTap:")
myPanGesture.delegate = self
newSticker.isUserInteractionEnabled = true
newSticker.addGestureRecognizer(myPanGesture)
func handleTap(sender: UIPanGestureRecognizer)
print("hi")
【问题讨论】:
UIPanGestureRecognizer(target: self, action: #selector(handleTap(_:)))
和 func handleTap(_ panGestureRecognizer: UIPanGestureRecognizer)
【参考方案1】:
问题是你没有指定选择器
let myPanGesture = UIPanGestureRecognizer(target: self, action: #selector(YourViewController.handleTap))
func handleTap()
print("hi")
希望这会有所帮助
【讨论】:
以上是关于以编程方式添加视图和手势 - “发送到实例的无法识别的选择器”的主要内容,如果未能解决你的问题,请参考以下文章
从 didSelectRowAtIndexPath 发送到实例的无法识别的选择器
TableView 中的集合视图显示项目 [VGS.CustumCell collectionView:numberOfItemsInSection:]:发送到实例的无法识别的选择器