ios – SwiftUI: View doesnt replace when Knowledge added to Realm DB by way of Sheet

0
8


I’m having a really irritating drawback, with my view and Realm DB. So I’ve a quite simple code, I’ve a view have been I show the saved Names in my Realm DataBase. These Names are saved by navigating to a different view by way of a navigationlink.

On this view a reputation is written in a Textfield and saved to the DB. After I return to my authentic View the title isnt being displayed, so I’ve to rerender my Simulator for it to replace and show the just lately added Title.

Any concepts on the right way to clear up this challenge?

That is my code:

That is my major view, the place the names ought to be displayed:

class Title: Object, ObjectKeyIdentifiable {
    @Endured(primaryKey: true) var id: ObjectId
    @Endured var title = ""
}


struct playground: View {
    
    @StateObject var nameManager = NameManager()
    @State var myName = ""
    @State var showSheet = false
    
    
    var physique: some View {
        NavigationView{
            VStack{
                NavigationLink(vacation spot: dataView(myName: $myName)) {
                    Textual content("go to a different view to put in writing title ")
                }
                
                
                ForEach(nameManager.names, id: .id) {title in
                    Textual content("(title.title)")
                        .onTapGesture {
                            nameManager.deleteName(id: title.id)
                        }
                }
                
            }.sheet(isPresented: $showSheet) {
                dataView(myName: $myName)
            }
        }
    }
}

And that is the view im utilizing to put in writing the title and retailer it:

struct dataView: View {
    @Binding var myName : String
    @StateObject var nameManager = NameManager()
    
    
    var physique: some View {
        
        VStack{
            TextField("Enter username...", textual content: $myName)
            
            
            Button("retailer to DB") {
                nameManager.addName(title: myName)
                myName = ""
                
                
            }
        }
        
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here