[英]How to add Context Menu into NavigationLink using SwiftUI?
I'm trying to add contextMenu into NavigationLink, using this code:我正在尝试使用以下代码将 contextMenu 添加到 NavigationLink 中:
NavigationLink(recent.name, destination: TextEditing(isNew: false, fileName: recent.name)).contextMenu{Button("Rename") {
// code
}
}
, but i receive swift compiler error: The compiler is unable to type-check this expression in reasonable time; ,但我收到 swift 编译器错误:编译器无法在合理的时间内对该表达式进行类型检查; try breaking up the expression into distinct sub-expressions
尝试将表达式分解为不同的子表达式
Try putting your code to execute in a separate function in your view struct and then call it from the context menu:尝试将代码放在视图结构中的单独函数中执行,然后从上下文菜单中调用它:
// put this in your view struct
func action() {
// code to run your menu action
}
And then call it from your context menu然后从上下文菜单中调用它
NavigationLink(recent.name, destination: TextEditing(isNew: false, fileName: recent.name)).contextMenu {
Button("Rename", action: action)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.