小编Rad*_*ast的帖子

UIHostingController 和 navigationController

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

swift swiftui xcode11

6
推荐指数
1
解决办法
2054
查看次数

标签 统计

swift ×1

swiftui ×1

xcode11 ×1