UIHostingController和navigationController

时间:2019-07-18 12:40:33

标签: swift swiftui xcode11

默认的swift项目,其中视图控制器嵌入了navigationController中,并推送到下一个UIHostingController。

如何从SimpleView调用navigationController?.popViewController?

ViewController:

@IBOutlet weak var button: UIButton?

override func viewDidLoad() {
    super.viewDidLoad()
    button?.addTarget(self,
                      action: #selector(showNewSwiftUIController),
                      for: .touchUpInside)
}

@objc func showNewSwiftUIController() {
    let vc = UIHostingController(rootView:SimpleView())
    navigationController?.pushViewController(vc, animated: true)
}

SwiftUI:

struct SimpleView: View {
    var body: some View {
        Text("SimpleView")
            .foregroundColor(.black)
    }
}

0 个答案:

没有答案