我想为 NavigationLink 添加一个额外的功能。
示例代码是这样的:
struct ContentView: View {
func yes () {
print("yes")
}
var body: some View {
NavigationView {
NavigationLink(destination: level1()) {
Text("Next")
}}}}
我知道这不起作用,但是有可能做这样的事情吗?(会去目的地,同时调用函数)
NavigationLink(destination: level1(), yes()) {Text("Next")}
我尝试在 NavigationLink 中放置一个按钮,但它也不起作用。当我这样做时,只有按钮中的功能起作用,NavigationLink 不起作用。
NavigationLink(destination: level1()) {
Button(action: { self.yes() })
{ Text("Button")}
}