默认的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)
}
}