当我在子级[SwiftUI]中解散rootViewController时,处理父级中的值

问题描述 投票:1回答:1

仅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)

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

有什么想法吗?

Ps。我想使用完成参数,但是我不知道如何阅读它

swift swiftui dismiss completionhandler
1个回答
1
投票
protocol ChildDelegate: class {
    func childWasDismissed()
}

class ChildController: UIViewController {
    var delegate: ChildDelegate?

    deinit {
        delegate?.childWasDismissed()
    }
}

类似的东西。或与闭包相同。

© www.soinside.com 2019 - 2024. All rights reserved.