向后滑动添加动作 Swift 5
Adding action to a back swipe Swift 5
在我的应用程序中,我有一个 UINavigationController,它在我的所有 ViewController 上放置了一个导航栏,并且在每个 ViewController 中我都有一个自定义后退按钮。在一个特定的 ViewController 中,我需要在返回到前一个 ViewController 时发送一些数据。当用户使用自定义功能按下后退按钮时,我能够执行此操作,但当用户滑动返回时,此功能将被忽略。
我尝试使用这个答案: 但是在导航控制器中调用 visibleViewController
或 topViewController
只会获取我们要访问的视图控制器(之前的 ViewController, 不是当前的)。在用户向后滑动之前,我需要我们所在的 ViewController 中的函数。
我如何调用我在当前 ViewController 中创建的 back
函数,将数据从 ViewController 发送到我们将弹出的 ViewController .
看来您只需要使用 viewWillDisappear(_:)
并将您制作的功能放在这里即可。
在我的应用程序中,我有一个 UINavigationController,它在我的所有 ViewController 上放置了一个导航栏,并且在每个 ViewController 中我都有一个自定义后退按钮。在一个特定的 ViewController 中,我需要在返回到前一个 ViewController 时发送一些数据。当用户使用自定义功能按下后退按钮时,我能够执行此操作,但当用户滑动返回时,此功能将被忽略。
我尝试使用这个答案:visibleViewController
或 topViewController
只会获取我们要访问的视图控制器(之前的 ViewController, 不是当前的)。在用户向后滑动之前,我需要我们所在的 ViewController 中的函数。
我如何调用我在当前 ViewController 中创建的 back
函数,将数据从 ViewController 发送到我们将弹出的 ViewController .
看来您只需要使用 viewWillDisappear(_:)
并将您制作的功能放在这里即可。