首页 > 解决方案 > 快速从弹出视图控制器中识别当前视图控制器

问题描述

假设我们有 2 个视图控制器

  1. FirstViewController.swift
  2. PopUpViewContraller.swift

PopUpViewContraller 已加载到 FirstViewController。现在如何从 PopUpViewContraller 调用 FirstViewController 中的函数。

标签: iosswift

解决方案


谢谢你回答我的问题。

最后,我得到了上述问题的解决方案。

我们可以使用通知中心来解决这个问题。

1)在弹出视图控制器()

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "botIsRemoved"), object: self)

2)在第一个视图控制器中

在 viewDidLoard() 里面

NotificationCenter.default.addObserver(self, selector: #selector(removeBotNow), name: NSNotification.Name(rawValue: "botIsRemoved"), object: nil)

并添加以下功能

@objc func removeBotNow(notification : Notification){

        // your tasks

    }

推荐阅读