【问题标题】:Is there a way for the MainViewController to know when a press IBAction function has been called? [closed]MainViewController 有没有办法知道何时调用了 press IBAction 函数? [关闭]
【发布时间】:2020-02-24 22:56:04
【问题描述】:

我有一个自定义 UIView,它有一个 press 方法。这是添加到主 Google mapView 的子视图。调用此方法时,我想调用一个函数或在主 ViewController 中设置一个全局变量。

任何反馈都将不胜感激。

【问题讨论】:

  • 一种可能的选择是使用委托模式。
  • ... 或闭包。

标签: ios swift xcode uiview


【解决方案1】:
  1. 每当调用press 方法时,内置NotificationCenter API 到broadcast 的通知。

    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)
  1. 代表:一对一。在这里阅读更多 - https://medium.com/@jamesrochabrun/implementing-delegates-in-swift-step-by-step-d3211cbac3ef

【讨论】:

    猜你喜欢
    • 2019-11-17
    • 2019-01-04
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 2019-03-21
    • 2014-02-22
    • 2019-05-18
    相关资源
    最近更新 更多