ios - 如何从关闭命令访问以前的 View Controller

标签 ios swift xcode uiviewcontroller presentviewcontroller

在我的整个应用程序中,我使用导航 Controller 来推送和弹出我的 View Controller 。当我从一个 ViewController 中弹出时,我检查是否可以使用以下方法重新加载前一个 ViewController 中的数据:

_ = self.navigationController?.popViewController(animated: true) 如果让 previousViewController = self.navigationController?.viewControllers.last 作为?动物VC { previousViewController.tableView.reloadData() }

这每次都有效,但现在我需要对另一个 View 执行相同的操作,但它不是导航 Controller 的一部分,因为我以模态方式呈现(而不是将其推送到导航 Controller )。现在我无法像以前那样访问以前的 ViewController,我不知道如何访问以前的 ViewController。

如何在不访问导航 Controller 的情况下访问以前的 ViewController 以像示例代码一样重新加载 tableview?

我知道这可以通过通知实现,但我宁愿尽可能不使用这种方法!

最佳答案

首先,没有必要访问以前的ViewController 来重新加载tableview(或任何其他功能)

我建议您使用Delegate 来实现相同的功能。

以您提到的方式持有对先前 viewController 的引用将使您的应用在变得更加复杂时很难维护。

关于ios - 如何从关闭命令访问以前的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57763822/

相关文章:

ios - 在 iOS 中应用程序从锁屏解锁到我的应用程序屏幕时的回调函数是什么?

ios - 使用动态增加的单元格计算 TableView 的内容大小

swift - Xcode 6x 和 7x 之间的 configureCell 不同

iphone - 在不 Release模式 View Controller 的情况下使用 dismissModalViewControllerAnimated

Xcode 无法加载 libvulkan.1.dylib

swift - 在 Xcode 8 中将物理赋予 SKTileMapNode 的图 block

iphone - 将日期解析为时间戳

ios - 在应用程序中快速查看推送通知

ios - 找不到适合 iPhone5 架构的图片

ios - 在 Swift 中使用 AFNetworking 接收响应