ios - 保持任务在 View Controller 之间运行

标签 ios swift

我正在寻找有关 Swift iOS 项目场景的一些提示。

所以我有一个 Modal view controllerMKMapView,我需要这个 Modal view controller 在它不是主视图 Controller 时运行,它被解雇了。 当它不是主视图 view controller 时,我如何让它保持运行和更新。

任何帮助将不胜感激。

最佳答案

你只需要保留一个strong reference到模态视图 Controller , 注意只实例化它一次,并在每次必须显示它时检查它是否存在。

例子:

import UIKit

class ViewController: UIViewController {
    var mapVc:MapViewController? // strong reference here

    @IBAction func showMapVc() {
        if self.mapVc == nil {
            self.mapVc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MapVC") as? MapViewController
        }
        self.present(self.mapVc!, animated: true, completion: nil)
    }
}

class MapViewController: UIViewController {
    @IBAction func closeVc() {
        self.dismiss(animated: true, completion: nil)
    }
}

关于ios - 保持任务在 View Controller 之间运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48879993/

相关文章:

ios - 如何本地化 iOS 应用程序的名称

ios - 如何将 subview 放在不同屏幕的正确位置

ios - UITextFieldDelegate "shouldChangeTextInRange"未调用

ios - cocoa touch : Multiple line text input

swift - 在 Swift 5 中,比较指向两个闭包的指针的方法是什么?

ios - 来自 URL 的图像请求失败

ios - NSDateFormatter 显示不正确的月份

ios - swift 3 : Append to UITextField while Editing Changed

ios - 日期到毫秒并在 Swift 中返回日期

ios - 在 Firebase 中使用访问代码的模式