MainViewController 有没有办法知道何时调用了按下 IBAction 函数? [英] Is there a way for the MainViewController to know when a press IBAction function has been called?
本文介绍了MainViewController 有没有办法知道何时调用了按下 IBAction 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义 UIView,它有一个 press
方法.这是添加到主 Google mapView 的子视图.调用此方法时,我想在主 ViewController 中调用函数或设置全局变量.
I have a custom UIView which has a press
method. This is a subview added to the main Google mapView. When this method is called, I would like to either call a function or set a global variable in the main ViewController.
任何反馈将不胜感激.
推荐答案
内置
NotificationCenter
API,用于在调用press
方法时广播
通知.
Built-in
NotificationCenter
API tobroadcast
notifications whenever thepress
method is called.
let nofitication = NotificationCenter.default
nofitication.post(name: Notification.Name("pressMethodCalled"), object: nil)
注册通知:
nofitication.addObserver(self, selector: #selector(your_method_name), name: Notification.Name("pressMethodCalled"), object: nil)
- 代表:一对一.在这里阅读更多 - https://medium.com/@jamesrochabrun/implementing-delegates-in-swift-step-by-step-d3211cbac3ef
这篇关于MainViewController 有没有办法知道何时调用了按下 IBAction 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文