如何在不触发NavigationLink事件的情况下在列表中添加可点击的按钮? [英] How to add a clickable button in a List without triggering NavigationLink event?
本文介绍了如何在不触发NavigationLink事件的情况下在列表中添加可点击的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在列表项中有一个按钮,当我单击它时,也会触发NavigationLink的事件.我只想触发按钮事件.怎么做?以下是我的代码:
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!)")
}
}
}
推荐答案
为按钮添加 PlainButtonStyle
,如下例所示
Add PlainButtonStyle
for button, as in below example
Button("新增记录"){
self.care = care
self.showSheetNewMark.toggle()
}
.buttonStyle(PlainButtonStyle()) // << here !!
这篇关于如何在不触发NavigationLink事件的情况下在列表中添加可点击的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文