所以我是 SwiftUI 的新手
我试图在我的视图中有一个表单,我有一个选择器遍历枚举。但是当我点击选择器开始它变灰并且什么都不做时,我必须离开视图然后回来。
我已经将我的选择器包装在导航视图中,它第二次起作用了,所以我不认为就是这样。我不确定还有什么可以尝试的。
这是我的快速视图
import SwiftUI
enum TestEnum: String, Equatable, CaseIterable {
case MORNING = "Morning"
case BREAKFAST = "Breakfast"
case LUNCH = "Lunch"
case AFTERNOON = "Afternoon"
case DINNER = "Dinner"
case EVENING = "Evening"
case BEDTIME = "Bedtime"
case OTHER = "Other or As Needed"
var id: String { rawValue }
var localizedName: LocalizedStringKey { LocalizedStringKey(rawValue) }
}
struct FormPage: View {
@State var selection = TestEnum.AFTERNOON
var body: some View {
VStack{
Text("Some Text")
NavigationView {
Form {
Picker("When do you take this", selection: $selection) {
ForEach(TestEnum.allCases, id: \.id) { value in
Text(value.rawValue)
.tag(value)
}
}
}
}.navigationViewStyle(StackNavigationViewStyle())
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
}
}
struct FormPage_Previews: PreviewProvider {
static var previews: some View {
FormPage()
}
}
struct ContentView: View {
@State private var currentTab = 0
var body: some View {
TabView(selection: $currentTab,
content: {
Text("One")
.tag(0)
.padding()
FormPage()
.tag(1)
.padding()
})
.tabViewStyle(PageTabViewStyle())
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .never))
.animation(.default)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
@main
struct testApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}