默认 swift 项目,视图控制器嵌入在 navigationController 中并推送到下一个 UIHostingController。
如何从 SimpleView 调用 navigationController?.popViewController ?
视图控制器:
@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)
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特用户界面:
struct SimpleView: View {
var body: some View {
Text("SimpleView")
.foregroundColor(.black)
}
}
Run Code Online (Sandbox Code Playgroud)