当我从另一个类调用时,无法识别的选择器发送到实例

问题描述

当我从另一个类中调用识别器时,会出现此错误无法识别的选择器已发送到实例, 如果您在同一个班级没打错电话

var orderViewCard = OrderVC()

let tapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(orderViewCard.handleCardTap(recognzier:)))
orderViewCard.handleArea.addGestureRecognizer(tapGestureRecognizer)

在OrderVC中:

@objc
    func handleCardTap(recognzier:UITapGestureRecognizer) {
        switch recognzier.state {
        case .ended:
            animateTransitionIfNeeded(state: nextState,duration: 0.9)
        default:
            break
        }
}

解决方法

您需要做的是相应地选择目标

     var orderViewCard = OrderVC()

    let tapGestureRecognizer = UITapGestureRecognizer(target: orderViewCard,action: #selector(orderViewCard.handleCardTap))
    orderViewCard.handleArea.addGestureRecognizer(tapGestureRecognizer)