Im trying to put checkmark when menu item selected.I tried give a @State var selectedSort : Int = .zero and give id(selectedSort) but It didn't work. How can I solve this problem ?
This is my code;
struct SortMenuPickerView : View {
@Binding var sortClicked : Bool
@ObservedObject var productListViewModel = ProductListViewModel()
@State var sortListArray : [ProductListSortAndFilterList]
var function: () -> Void
@Binding var sortId : String
var body : some View {
HStack(alignment: .center){
Spacer()
Menu {
ForEach(sortListArray,id:\.id){ item in
if item.id == "sort" {
ForEach(item.sortList ?? [],id:\.id) { data in
Button(action: {
sortId = (data.id ?? "")
self.function()
print("selected item is : \(data.id!)")
}) {
Text(data.name ?? "")
.tag(data.id)
}
}
}
}
} label: {
SortView()
}
Try with picker style menu & can customise with your requirements...
Its sample example: