如何让按钮在列表中单击不会触发Navigationlink事件?

问题描述 投票:0回答:1

我在列表项中添加了一个按钮,当我单击该按钮时,navigationLink的clickEvent触发器也会触发。当我只想触发按钮的clickEvent时,该怎么办?以下是我的代码:

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!)")
          }
          }
    }
swift list button swiftui navigationlink
1个回答
0
投票

为按钮添加PlainButtonStyle,如下例所示>>

Button("新增记录"){
  self.care = care
  self.showSheetNewMark.toggle()
}
.buttonStyle(PlainButtonStyle()) // << here !!
© www.soinside.com 2019 - 2024. All rights reserved.