【问题标题】:Generic function to pop or dismiss ViewController in iOS & iPadOS just like show() & showDetail()在 iOS 和 iPadOS 中弹出或关闭 ViewController 的通用函数,就像 show() 和 show Detail()
【发布时间】:2021-10-18 19:52:33
【问题描述】:

就像我们有 show(_ vc: UIViewController, sender: Any?)showDetailViewController(_ vc: UIViewController, sender: Any?) 来推送和呈现 ViewController,无论它们是嵌入在 UINavigationController 还是 UISplitController 中。

我们是否有类似这些通用的东西来弹出/关闭 ViewController ?

【问题讨论】:

    标签: ios swift uinavigationcontroller uikit uisplitviewcontroller


    【解决方案1】:

    我不确定我明白你在问什么......

    有一个名为dismiss(animated: Bool, completion: (() -> Void)?)UIViewController 函数和navigationController?.popViewController(animated: Bool)。

    如果您正在寻找可以做的事情,我想它看起来像

    extension UIViewController {
        func dismissPop(animated: Bool) {
            if let navigationController = navigationController {
                navigationController.popViewController(animated: animated)
            } else {
                dismiss(animated: animated)
            }
        }
    }
    

    如有必要,也可以添加完成处理程序。

    【讨论】:

      猜你喜欢
      • 2015-02-16
      • 2014-12-04
      • 2023-04-11
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      相关资源
      最近更新 更多