I have a simple app I'm working on.
There is a data model which is stored in an environment object.
The app has an array of people, and each person has an array of events associated with them.
So, I have a Person Detail view with an edit button which presents a Person Edit view via a navigation link. The edit view has a save button which updates the environment object model and dismisses the view.
This works.
On the Person Detail view there is a list of events. Tapping on an event takes you to an Event Detail view. With almost exactly the same code, there is a Edit Event Detail view that is triggered by an Edit button in the same manner as above. The model is updated in the same way and the view is dismissed. B
Here's the pain point - when you go from a Person Edit view to Person Detail view, it updates the information on the Person Detail View.
On the Event side, after a save, the Event Detail view is not updated. You can go back up the stack and re-enter the Event Detail view and the data is updated.
Here's what's driving me insane. This is on an iOS simulator and real device.
If I try it on an iPad, same code, same views, same everything both views update correctly.
Person Detail:
....
Person Edit:
Event Detail:
...
Event Edit:
Since the code for the Person view is the same as the event view, I just can't understand if the event view is wrong, how does the person view work?
How can the code work on iPad but not iPhone - with the same view code/navigation code. Am I just hitting a bug in the beta?
There is a data model which is stored in an environment object.
The app has an array of people, and each person has an array of events associated with them.
So, I have a Person Detail view with an edit button which presents a Person Edit view via a navigation link. The edit view has a save button which updates the environment object model and dismisses the view.
This works.
On the Person Detail view there is a list of events. Tapping on an event takes you to an Event Detail view. With almost exactly the same code, there is a Edit Event Detail view that is triggered by an Edit button in the same manner as above. The model is updated in the same way and the view is dismissed. B
Here's the pain point - when you go from a Person Edit view to Person Detail view, it updates the information on the Person Detail View.
On the Event side, after a save, the Event Detail view is not updated. You can go back up the stack and re-enter the Event Detail view and the data is updated.
Here's what's driving me insane. This is on an iOS simulator and real device.
If I try it on an iPad, same code, same views, same everything both views update correctly.
Person Detail:
Code Block struct PersonDetailView: View { var person:Person @EnvironmentObject var model:DataStore @State private var selectedSection = 0 var body: some View {
....
Code Block NavigationLink(destination: EditPersonView(personId:person.id, person: person) ){
Person Edit:
Code Block struct EditPersonView: View { var personId:UUID @State var person:Person @EnvironmentObject var model:DataStore @Environment(\.presentationMode) var presentation var body: some View {
Code Block Button(action: { model.updatePerson(id: person.id, newLastName: person.lastName, newGivenName: person.givenName, newNickName: person.nickName, newGender: person.gender); presentation.wrappedValue.dismiss() }, label: { Text("Save") })
Event Detail:
Code Block struct LifeEventDetailView: View { var lifeEvent:LifeEvent var person:Person @State var coordinates:MKCoordinateRegion @EnvironmentObject var model:DataStore var body: some View {
...
Code Block NavigationLink(destination: EditLifeEventView(person: person, eventId: lifeEvent.id, event: lifeEvent)){
Event Edit:
Code Block struct EditLifeEventView: View { var person:Person var eventId:UUID @State var event:LifeEvent @EnvironmentObject var model:DataStore @Environment(\.presentationMode) var presentation
Code Block Button("Save", action: { model.updateLifeEvent(id: event.id, type: event.type, primaryPerson: person.id, secondaryPerson: event.secondaryPerson, date: event.date, location: event.location, notes: event.notes) presentation.wrappedValue.dismiss() })
Since the code for the Person view is the same as the event view, I just can't understand if the event view is wrong, how does the person view work?
How can the code work on iPad but not iPhone - with the same view code/navigation code. Am I just hitting a bug in the beta?