我使用MVVM(rxswift)。进入我的MainPageView中,我将func cellForItemAt称为pagerView。在那里我添加了tapGestureRecognizer ...
进入cellForItemAt我调用下一个代码:
let webUrl = images[index]
let tapGestureRecognizer = MyTapGesture(target: self, action: #selector(imageTapped(sender:)))
tapGestureRecognizer.webUrl = webUrl
cell.imageView?.addGestureRecognizer(tapGestureRecognizer)
在我调用了Objective-c函数
之后@objc func imageTapped(sender: MyTapGesture){
guard let model = sender.webUrl else { return }
print(model)
sender.openDetailPartner(with: model)
}
和手势类别:
class MyTapGesture: UITapGestureRecognizer,Stepper {
var webUrl: PartnersItem? = nil
(// this func doesn't call func openPartnersInfoController , but this code works in another viewController)
func openDetailPartner(with model: PartnersItem) {
step.accept(AppStep.openPartnersInfoController(partners: model, showType: .push))
}
}