1

如何解决出现警告的原因?

struct ContentView: View {

    @State private var selectedDate: Date = Date()

    var body: some View {
        Form {
            DatePicker("Date", selection: $selectedDate, displayedComponents: .date)
        }
    }
}
4

1 回答 1

4

一种解决方法是使用ListView 而不是Form. 这完全取决于你想在你的Form. 出于演示目的,使用 a List,您的代码将如下所示:

struct ContentView: View {

    @State private var selectedDate: Date = Date()

    var body: some View {
        List {
            DatePicker("Date", selection: $selectedDate, displayedComponents: .date)
        }
        .listStyle(InsetGroupedListStyle())
    }
}

上面给出的视觉效果(UI)与使用 a 相同List,并且没有显示警告。

因为一切都与你的工作正常Form,我真的不认为有必要将你的更改FormList只是为了避免日志。

于 2021-05-13T08:18:21.867 回答