Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI List rows in Edit Mode do not allow Buttons actions/NavigationLinks to work?

SwiftUI List rows in Edit Mode do not allow Buttons actions to work I note (as well as NavigationLinks too). Is there a way to get this working?

Goal - Want to have NavigationLink or Modal view to the following depending on the edit mode. This relies on the ability to have button actions/nav links working in Edit Mode. (if there's another way to achieve my goal happy to have pointers)

  1. Not Edit Mode: Click on row => Detailed view for this record
  2. In Edit Mode: Click on row => Edit view for the master record name (e.g. rename)

Code (just to highlight the button doesn't work in Edit Mode):

   List() {
        ForEach(gcLists) { gcList in
            HStack {
                Button(gcList.title) {
                    print("button pressed!")
                }
            }
        }
        .onDelete(perform: deleteList)
        .onMove(perform: move)
    }
like image 340
Greg Avatar asked Dec 24 '19 07:12

Greg


1 Answers

I used previously the following approach, please try

Button(action: {}) {
  // label content here
}
.onTapGesture {
  // action here
}
like image 133
Asperi Avatar answered Nov 07 '22 11:11

Asperi