一旦详细视图完全呈现,时钟将冻结。
如果你List
用ScrollView
/替换,VStack
传播将会流动。
struct ContentView: View {
@State private var clocks = [Date(), Date(), Date()]
var body: some View {
NavigationView {
List {
ForEach(clocks.indices) { idx in
NavigationLink(destination: Text(clocks[idx], formatter: formatter)) {
Text("Counter \(idx)")
}
}
}
}
.onReceive(Timer.publish(every: 1, on: .main, in: .default).autoconnect()) {
clocks[0] = $0
clocks[1] = $0
clocks[2] = $0
}
}
var formatter: DateFormatter {
let formatter = DateFormatter()
formatter.timeStyle = .medium
return formatter
}
}