简体   繁体   English

如何通过UITapGestureRecognizer将数据从一个UIViewController传递到另一个UIViewController

[英]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.

相关问题 如何将字符串从一个uiviewcontroller传递到另一个 - how to pass a string from one uiviewcontroller to another 如何将值从一个UIViewController传递到另一个 - How to pass a value from one UIViewController to another 如何从一个Containerview传递到另一个UIViewController - How to pass from one Containerview to Another UIViewController 将数据从一个UIViewController委派给另一个UIViewController - Delegate data from one UIViewController to another one 如何通过parentviewController将数据从一个视图传递到另一个视图 - how to pass data from one view to another view through parentviewcontroller 如何从另一个事件发送事件到UIViewController - How to send an event to UIViewController from another one 在另一个UIViewController中使用一个UIViewController中的UIView? - Using an UIView from one UIViewController in another UIViewController? 在另一个UIViewController中处理UITapGestureRecognizer - Handle UITapGestureRecognizer in another UIViewController 如何通过NSNotification将消息从一个类传递到另一个类 - How to pass messages from one class to another through NSNotification 如何以编程方式从一个UIViewController切换到另一个,而无需模态或Push? - How to programmatic segue from one UIViewController to another without Modal or Push?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM