[英]How to pass data from one UIViewController to another one through UITapGestureRecognizer
I have a custom a UIView which is in the form of a card. 我有一个自定义的UIView卡形式。 Now I have placed a tap gesture recognizer on it so that when my user clicks on it, it will move to the selected view controller.
现在,我在其上放置了一个轻击手势识别器,以便当我的用户单击它时,它将移动到选定的视图控制器。 I have been able to achieve that and it is working well.
我已经能够实现这一目标,并且运行良好。 Now my problem is I want to pass data through this action so that the new view controller can access the data.
现在我的问题是我想通过此操作传递数据,以便新的视图控制器可以访问数据。
prepareSegue
is not working. prepareSegue
无法正常工作。 Below is my code: 下面是我的代码:
//Function to go to plans view controller
@objc func goToPlans(_sender: UITapGestureRecognizer) {
let moveTo = storyboard?.instantiateViewController(withIdentifier: "ChosenOfferViewController")
present(moveTo!, animated: true, completion: nil)
}
//Function to add gestures to the card
func addGesturesToCards() {
let planRec = UITapGestureRecognizer(target: self, action: #selector(self.goToPlans))
planCard.addGestureRecognizer(planRec)
}
Try this. 尝试这个。 Just cast your View Controller as your custom class and then pass your data in this way
只需将View Controller转换为自定义类,然后以这种方式传递数据
guard let moveTo = storyboard?.instantiateViewController(withIdentifier: "ChosenOfferViewController") as? ChosenOfferViewController else { return }
moveTo.someProperty = yourData
present(moveTo, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.