【问题标题】:Handling value in the parent when I dismiss a rootViewController in the child [SwiftUI]当我在子级 [SwiftUI] 中关闭 rootViewController 时处理父级中的值
【发布时间】:2020-08-03 06:22:34
【问题描述】:

仅 SWIFTUI

我正在使用UIHostingController,当我从父级关闭rootViewController 时我想处理

MAINVIEW** [家长]

let alertHostingController = UIHostingController(rootView: SettingsView())
                                alertHostingController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
                                UIApplication.shared.windows[0].rootViewController?.present(alertHostingController, animated: false)

SETTINGS VIEW** [孩子]

 UIApplication.shared.windows[0].rootViewController?.dismiss(animated: true, completion: nil)

我想知道孩子何时在父母中被解雇...

有什么想法吗?

附言。我想用completion参数但是不知道怎么读

【问题讨论】:

    标签: swift swiftui dismiss completionhandler


    【解决方案1】:
    protocol ChildDelegate: class {
        func childWasDismissed()
    }
    
    class ChildController: UIViewController {
        var delegate: ChildDelegate?
    
        deinit {
            delegate?.childWasDismissed()
        }
    }
    

    类似的东西。或者闭包也一样。

    【讨论】:

    • 没有。您应该将其添加到您的孩子中,并使父母符合 ChildDelegate。
    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 2021-06-13
    • 2021-11-26
    • 1970-01-01
    • 2017-08-13
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多