Hello,
I'm a few weeks into learning SwiftUI, and I'm making an iOS app that allows users to save their online meeting links in a list. I have two buttons in each row of the list, one that lets users join directly from their phone and another that opens a UIActivityViewController to let them AirDrop the link to their Mac.
The problem is: whenever I click anywhere on the row (not on the button) it triggers the actions for both buttons. Clicking either of the buttons also triggers both button actions. My code example is below. I made the two buttons print different values for now so it's easier to tell what's going on.
I want each button click to only register the action of that button, and I don't want the whole row to be clickable. Maybe I shouldn't be using navigation view? I would prefer to keep using navigation view because it lets me add a title and navigationBarItems
I'm a few weeks into learning SwiftUI, and I'm making an iOS app that allows users to save their online meeting links in a list. I have two buttons in each row of the list, one that lets users join directly from their phone and another that opens a UIActivityViewController to let them AirDrop the link to their Mac.
The problem is: whenever I click anywhere on the row (not on the button) it triggers the actions for both buttons. Clicking either of the buttons also triggers both button actions. My code example is below. I made the two buttons print different values for now so it's easier to tell what's going on.
Code Block NavigationView { List { ForEach(items) { item in HStack { VStack(alignment: .leading){ Text("\(item.name ?? "Untitled")") .font(.largeTitle) .padding(.top, 5.0) Text("Starts at \(item.time!, formatter: itemFormatter)") .padding(.bottom, 3.0) } Spacer() Button { print("Sending to computer") } label: { Image(systemName: "laptopcomputer.and.iphone") .padding() } Button { print("Joining on iPhone") } label: { Text("JOIN") .fontWeight(.semibold) .foregroundColor(Color.white) .padding(.trailing, 1.0) .frame(width: 60.0, height: 30.0) } } } .onDelete(perform: deleteItems) } .listStyle(InsetListStyle()) .navigationBarItems( leading: EditButton(), trailing: Button { addItem() } label: { Image(systemName: "plus") }) .navigationTitle("My Meetings") } }
I want each button click to only register the action of that button, and I don't want the whole row to be clickable. Maybe I shouldn't be using navigation view? I would prefer to keep using navigation view because it lets me add a title and navigationBarItems