问题
I have a button in a list item and when I click on it, the NavigationLink's event is also being triggered. I only want to trigger the button event. How to do it? following is my code:
ForEach(self.cares,id:\.id){ care in
HStack{
if(care.markMode == "打卡"){
Button("今日未打卡"){
}
else{
Button("新增记录"){
self.care = care
self.showSheetNewMark.toggle()
}
}
NavigationLink(destination:CareDetailView(care: care)){
Text("\(care.nickname!)的\(care.subject!)")
}
}
}
回答1:
Add PlainButtonStyle
for button, as in below example
Button("新增记录"){
self.care = care
self.showSheetNewMark.toggle()
}
.buttonStyle(PlainButtonStyle()) // << here !!
来源:https://stackoverflow.com/questions/61848190/how-to-add-a-clickable-button-in-a-list-without-triggering-navigationlink-event