Wednesday, December 7, 2022
HomeiOS Developmentios - SwiftUI Checklist Row Context Menu Label Primarily based on Index...

ios – SwiftUI Checklist Row Context Menu Label Primarily based on Index – Not Appropriate index


Searched round and haven’t discovered a solution. Imagine I do know what the difficulty is, however unsure methods to resolve it.

I’ve a swiftUI listing that shows a context menu when a sure kind of row is chosen(not all rows qualify, this works because it ought to. When the context menu is displayed, the label is generated by the index of the array populating the lists object property.

The context menu choice performs performs a process that ought to end result within the context menu label altering. And typically it really works, different occasions it doesn’t. That is resolved by scrolling that individual row off display screen and scrolling again too it (needs to be far sufficient away). The Object array is from a singleton knowledge retailer handed as an atmosphere object.

I consider that is associated to the scale of the array and the information being lazy loaded in swiftUI lists. I additionally would use the Checklist choice property for this, however the context menu being populated by the row doesn’t replace the lists chosen row.

A snippet instance of my code is beneath.

@EnvironmentObject var singletonStore: MyObjectStore
@State personal var selectedRow: Int?

var physique: some View {
    VStack {
            
                    Checklist(singletonStore.myArray.indices, id: .self, choice: $selectedRow) { index in
                        
                        LazyVGrid(columns: gridColumns) {
                            ItemGridView(merchandise: $singletonStore.myArray[index], opacityOffset: getRowOpacity(index: index))
                        }
                        .contextMenu {
                            if singletonStore.myArray[index].thisDate == nil {
                                if singletonStore.myArray[index].thisNeedsDone > 0 {
                                    Button {
                                        selectedRow = index
//these features will add or take away a customers id or initials to the suitable property, and this updates values in my listing view.

                                        if singletonStore.myArray[index].id != nil {
                                            //do that
                                        } else {
                                            //do this
                                        }
                                    } label: {
                                        Label{                     
//That is the place my difficulty is - although the objects within the listing view are updating, the label of the context menu will not be updating till the row is reloaded


Textual content(singletonStore.myArray[index].initials != nil ? "This Label" : "That Label") } icon: {
                                                Picture(systemName: "aqi.medium")
                                            }
                                    }
                                }
                            }
                        } //context menu shut
                    } // listing shut
                    .listStyle(PlainListStyle())
        }    
}

My closures could also be off, however its as a result of I modified the code considerably on this platform to make is less complicated to comply with. Nothing eliminated would have an effect on this difficulty.

if there was a method to have opening the context menu replace the lists chosen row, that will resolve the difficulty and I might use the chosen row for the index of the singletonStores array objects property, however I could also be approaching the issue from pondering the index is inaccurate when the precise difficulty is the context menu will not be being reloaded with the atmosphere objects new info. Any assistance is all the time appreciated!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments