Post

Replies

Boosts

Views

Activity

Reply to Picker with Unexpected Results
Consider this: struct PickColorView: View { @State private var number1: Int = 4 @State private var number2: Int = 0 let range: ClosedRange<Int> = 0...20 let array: Array<Int> = [14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60] var body: some View { NavigationView { Form { Picker(selection: $number1, label: Text("Number1")) { ForEach(range, id: \.self) { number in Text("\(number)") } } .onChange(of: number1) { newNumber1 in print("newNumber1: \(newNumber1)") } Picker(selection: $number2, label: Text("Number2")) { ForEach(array, id: \.self) { number in Text("\(number)") } } .onChange(of: number2) { newNumber2 in print("newNumber2: \(newNumber2)") } } .navigationBarTitle("Settings") .navigationBarHidden(false) } .navigationViewStyle(StackNavigationViewStyle()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Problems Updating a View
In NFCReader, the "data" that you are adding the new item to is not the same as the "data" in your ContentView. They are two separate objects. So the addition will never show up in your UI. You need to use a single "data", and pass it to wherever it is needed. For example... In ContentView, you could remove data, make NFCReader the StateObject, publish NFCReader's data, and refer to that data in your View.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22