I spent 14 hours trying to figure it out today, I went over here, googled, and watched videos but nothing helped. I gave up so I decided to ask a question.
Typically, I have two views in one, such as the list on the left and details on the right. On the iPhone, I was able to use the sheet to pop up the second view without any issues, but on the iPad, I have a second view on the right side and it does not update when I click on the list. I tried @Binging and @State, but it didn't work.
How can I pass data from one view to another?
The navigation link code:
let navigationItemList: [NavigationItems] = [NavigationItems(image: Image(systemName: "hourglass"), title: "Feature 1", subtitle: "Subtitle", linkView: AnyView(FeatureView1())),
NavigationItems(image: Image(systemName: "clock.arrow.2.circlepath"), title: "Feature 2", subtitle: "Subtitle", linkView: AnyView(FeatureView2()))]
struct ContentView: View {
var body: some View {
NavigationView {
List {
Section(footer: MainFooterView()) {
ForEach(navigationItemList) { items in
HStack {
items.image?
.frame(width: 30, height: 30)
.font(.system(size: 25))
.foregroundColor(color3)
Text("")
NavigationLink(items.title, destination: items.linkView)
}
.listRowBackground(Color.clear)
.listRowSeparatorTint(.clear)
}
.navigationTitle("Features")
.listStyle(.insetGrouped)
}
}
}
}
}
First view:
struct FeatureView1 : View {
var body: some View {
HStack {
List(item) { items in
Button("Click to update title in Feature View 2") {
FeatureView2(title: "Button Called") //Nothing happened
}
}
FeatureView2()
}
}
Second view:
var body: some View {
var title = ""
ZStack {
Text(title) //When I click a button from the list, it should show "Button Called", but nothing happens.
}
}