Hello guys,
I'm having a little problem again. After creating a new object, I would like to branch to a detaillier on the iPhone without any user action. But after adding the data there should be a manual possibility to come back. Is there a possibility for this? Unfortunately I have not found anything yet.
Thanks a lot.
The problem is shown in the code below:
import SwiftUI
class L: ObservableObject {
@Published var x = ["a", "b", "c"]
}
struct ContentView: View {
@ObservedObject var l = L()
var body: some View {
NavigationView {
List {
ForEach (l.x, id: \.self) {x in
NavigationLink(destination: sv()) {
Text(x)
}.navigationBarTitle(Text("List"))
.navigationBarItems(trailing: Button(action: self.addnewvalue, label: { Text("New")}))
}
}
}
}
func addnewvalue() {
l.x.append("d")
//how to get automatically into the detailview sv?
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct sv: View {
var body: some View {
Text("Hello, World!")
//how to get back with buttom into the main view?
}
}