gpt4 book ai didi

ios - SwiftUI 工具栏未显示在 NavigationLink View 上

转载 作者:行者123 更新时间:2023-12-01 21:19:19 27 4
gpt4 key购买 nike

我试图在导航链接内部的 View 上显示工具栏。当我导航到第三个 View 时,我收到以下消息:

2020-09-15 23:09:31.097289-0500 CountTime[35018:3542166] [Assert]displayModeButtonItem is internally managed and not exposed forDoubleColumn style. Returning an empty, disconnected UIBarButtonItemto fulfill the non-null contract.

并且未显示工具栏。这只发生在 iPhone 上,不会发生在 iPad 上。我正在使用 Xcode 12 GM。

代码如下:

struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(
destination: SecondView(),
label: {
Text("Navigate")
})
}
}
}

struct SecondView: View {
var body: some View {
ZStack {
NavigationLink(
destination: Text("Destination")
.toolbar {
ToolbarItem(placement: ToolbarItemPlacement.bottomBar) {
Button(action: {
print("sharing")
}) {
Image(systemName: "square.and.arrow.up")
}
}
},
label: {
Text("Navigate")
})
}
}
}

最佳答案

displayModeButtonItem is internally managed and not exposed forDoubleColumn style

在您的情况下,SwiftUI 出于某种原因尝试以 DoubleColumn 样式呈现 NavigationView。

一种可能的解决方案是明确指定样式:

struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: SecondView()) {
Text("Navigate")
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
}

关于ios - SwiftUI 工具栏未显示在 NavigationLink View 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63924764/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com