本文介绍了触摸栏中的SwiftuUI NavigationLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试借助SwiftUI在MacBook touchBar中创建NavigationLink.实际上,在我的代码段中,按钮显示在触摸栏中,但不幸的是,该链接不起作用.
I'm trying to create NavigationLink in MacBook touchBar with help of SwiftUI. Actually with my piece of code, the button is shown in touchbar, but unfortunately the link doesn't work.
NavigationView {
.touchBar {
NavigationLink(destination: BookView()) {
Text("GoToBook")
}
}
}
struct BookView: View {
var body: some View {
Text("Hello")
}
}
推荐答案
请尝试使用touchBar中的 Button
(以编程方式激活 NavigationLink
,如下所示)
Try instead with Button
in touchBar activating NavigationLink
programmatically, like below
@State private var isActive = false
...
// below in body
NavigationView {
SomeView() // << your view here
.background(NavigationLink(destination: BookView(), isActive: $isActive) {
EmptyView()
} // hidden link
)
.touchBar {
Button("GoToBook") { self.isActive.toggle() } // activate link
}
}
这篇关于触摸栏中的SwiftuUI NavigationLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!