如何在 SwiftUI 中初始化 Binding : Bool 变量?
How to initialize a Binding : Bool variable in SwiftUI?
如何初始化shouldPopToRootView
?这是我的代码:
import SwiftUI
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
init() {
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
}
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
}
}
}
}
看看这个:
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
init(shouldPopToRootView: Binding<Bool>) {
self._shouldPopToRootView = shouldPopToRootView
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
} // I get the error here
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
}
}
}
}
struct ContentView: View {
var body: some View {
DoctorHomePage(shouldPopToRootView: .constant(true))
}
}
如何初始化shouldPopToRootView
?这是我的代码:
import SwiftUI
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
init() {
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
}
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
}
}
}
}
看看这个:
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
init(shouldPopToRootView: Binding<Bool>) {
self._shouldPopToRootView = shouldPopToRootView
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
} // I get the error here
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
}
}
}
}
struct ContentView: View {
var body: some View {
DoctorHomePage(shouldPopToRootView: .constant(true))
}
}