You can use Callback function also to get tap action on your parrentViewController:
1) Declare callback function into your view:
var callback:(() -> Void)?
You can also pass any value from your view like (var callback:((String) -> Void)?). I take string here you can pass as you want.
and in button action call this function like this (callback?("i am passing string here"))
2) Call this function in your IBAction of button:
@IBAction func btnClick(_ sender: Any) {
callback?()
}
3) Write callback function closure in your parrentViewControler:
class ParentViewController: UIViewController {
@IBOutlet var myCustomView: MyView!
override func viewDidLoad() {
super.viewDidLoad()
viewTapped()
}
func viewTapped() {
myCustomView.callback = { [unowned self]
//you will get button tap action here
let ctrl = FirstViewController()
self.present(ctrl, animated: true, completion: nil)
}
}
}