You're creating a brand new WebViewController
, but you should have the reference for your actual WebViewController
. You could create a delegation connection like:
protocol CardViewControllerDelegate: AnyObject {
func didClickSaveButton()
}
Then make it settable in CardViewController
:
class CardViewController {
....
weak var delegate: CardViewControllerDelegate?
....
}
and let WebViewController
implement that:
extension WebViewController: CardViewControllerDelegate {
func didClickSaveButton() {
// handling code
print("save button tapped")
tapCallback?()
}
Then, set the delegate when you create CardViewController
in WebViewController
:
func showCardViewController() { // or whatever the name is
let cardVC = CardViewController() // or however you load it
cardVC.delegate = self
present(cardVC, animated: true) // or however you show it
}
Lastly, connect to the delegate:
@IBAction func backBtn(_ sender: Any) {
delegate?.didClickSaveButton()
}
If the view controllers are made in Storyboard, and there's a segue between them, you could set the delegate in prepareForSegue
, like:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let cardViewController = segue.destination as? CardViewController {
cardViewController.delegate = self
}
}