Hey, I created a custom view for a list item. at its own file the buttons work but when I use the view on my list view, it does not work. Can someone explain to me why it is not working?
import SwiftUI
struct itemBox: View {
@ObservedObject var item = Item(itemName: "", itemCount: 0)
var body: some View {
VStack{
Text("\(item.itemName ?? "Enter Name")")
.padding([.top, .leading, .trailing])
HStack {
Button ( action:{
item.add()
}, label: {
Image(systemName: "arrowtriangle.up.square.fill")
.frame(width: 19.0, height: 19.0)
.imageScale(.large)
.foregroundColor(.accentColor)
})
.padding([.leading, .bottom])
Text("\(item.itemCount)")
Button ( action:{
item.sub()
}, label: {
Image(systemName: "arrowtriangle.down.square.fill")
.frame(width: 19.0, height: 19.0)
.imageScale(.large)
.foregroundColor(.accentColor)
.background(item.itemCount == 0 ? Color.gray : Color.blue)
}).padding([.bottom, .trailing]) .disabled(item.itemCount == 0)
}
}.frame(width: 100.0, height: 100.0)
.border(/*@START_MENU_TOKEN@*/Color.yellow/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/6/*@END_MENU_TOKEN@*/)
}
}
import SwiftUI
struct ContentView: View {
@State private var showingPopup = false
@ObservedObject var item = Item(itemName: "", itemCount: 0)
var body: some View {
NavigationStack{
List(Item.sample) { item in
itemBox(item: item)
} .toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
Button("Add new") {
self.showingPopup = true
print("dsds")
}.sheet(isPresented: $showingPopup, content: {
ListView()
})
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button("Item List") {
self.showingPopup = true
print("dsds")
}.sheet(isPresented: $showingPopup, content: {
ListView()
})
}
}
.navigationBarBackButtonHidden(true)
}
}
}