どうも、ちょげ(@chogetarou)です。
「シートでForm内のピッカーが機能しない!」という人に向けて、
その解決方法を紹介します。
解決方法

シートでForm内のPickerを機能させるには、NavigationViewを使います。
具体的には、FormをNavigationViewでラップします。
NavigationView {
Form {
・・・・
}
}
NavigationViewでFormを囲むことで、Form内のピッカーが機能するようになります。
使用例
struct ContentView: View {
@State private var selectedIndex = 0
@State private var isShow = false
var body: some View {
VStack {
Button("Show Sheet") {
self.isShow.toggle()
}
.sheet(isPresented: $isShow) {
NavigationView {
Form {
Picker("Select", selection: $selectedIndex) {
ForEach(1..<10) {
Text("Item \($0)")
}
}
}
}
}
}
}
}
コメント