我正在用一个按钮展示和关闭一个 swiftUI 视图,它工作正常。
swiftUI 视图:
struct SmartG_SwiftUI: View {
var dismissAction: (() -> Void)
var body: some View {
Button(action: {
dismissAction()
}) {}
}
}
我以这种方式展示来自 UIKit 的 SwiftUI 视图控制器:
let hostingVC = UIHostingVC(rootView: SmartG_SwiftUI(dismissAction: {
vc?.dismiss( animated: true, completion: nil )
}))
vc?.present(hostingVC, animated: true, completion: nil)
我的问题是,我怎么能把这个按钮放在一个单独的结构中?所以为了有类似的东西:
struct SmartG_SwiftUI: View {
var dismissAction: (() -> Void)
Header()
}
struct Header: View {
Button(action: {
dismissAction() //unknown here
}) {}
}