In my app, I have two buttons at the top of the screen that are designed to open two different views as follows:
struct ContentView: View {
@State private var showingSheet = false
var body: some View {
VStack {
ZStack {
Image("top_toolbar")
.resizable()
.frame(width: 375, height: 90, alignment: .center)
HStack {
Button(action: {
showingSheet.toggle()
}, label: {
Image(systemName: "list.bullet")
})
.sheet(isPresented: $showingSheet) {
MenuView()
}
Spacer()
Button(action: {
showingSheet.toggle()
}, label: {
Image(systemName: "magnifyingglass")
})
.sheet(isPresented: $showingSheet) {
SearchView()
}
}
}
MainView()
}
}
}
The separate view files (MenuView and SearchView) both look great in the Preview canvas. When I run a live preview, tapping on the button linking to MenuView does as designed and opens MenuView in a sheet. However, tapping on the button linking to SearchView opens up MenuView. Xcode build is successful: not sure why the button for SearchView is not working properly.
Any help to correct would be greatly appreciated. Thank you in advance.