问题描述
每次导航到另一个屏幕时,我都会在控制台中收到此消息:
[Assert] displayModeButtonItem is internally managed and not exposed for DoubleColumn style. Returning an empty,disconnected UIBarButtonItem to fulfill the non-null contract.
目前,我已经在应用的入口点设置了导航视图,
NavigationView {
KeyboardView(matrixVM: matrixVM,isNavigationBarHidden: $isNavigationBarHidden)
.background(Color("background")
.edgesIgnoringSafeArea(.all))
.navigationBarTitle("Workspace")
.navigationBarHidden(self.isNavigationBarHidden)
.onAppear {
self.isNavigationBarHidden = true
}
}
然后在KeyboardView中有导航链接
NavigationLink(destination: NotebookView(isNavigationBarHidden: $isNavigationBarHidden,saved: matrixVM),label: {
Text("Notebooks")
.font(.system(size: 14,design: .rounded))
.fontWeight(.medium)
.foregroundColor(Color("text"))
.padding(.trailing,10)
})
在NotebookView中,我有一个导航链接列表(每个笔记本都链接到其详细信息页面)
ScrollView(showsIndicators: false) {
ForEach(notebooks,id: \.self) { notebook in
NavigationLink(destination: ExpandedSnippet(matrixVM: saved,notebook: notebook)
.navigationBarTitle("Notebook",displayMode: .inline)) {
SnippetCard(notebook: notebook,matrixVM: saved)
.frame(width: UIScreen.main.bounds.width)
}
.padding(.bottom,30)
}
}
一切似乎都可以正常运行,但是仅在几个小时前却没有运行(我使用的是Tabbar,工作了几周后突然开始崩溃)。我觉得这有点乱,我做错了什么。知道为什么吗?感谢您的帮助!
解决方法
使用Xcode 12.1(12A7403),此问题似乎是固定的。
为后代保留的先前答案仍在下面。
我也使用最新的Xcode 12 beta(12A8189)遇到了这个问题。
这提供了一个简单的MVP来演示问题。
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: DetailView()) {
Text("First View")
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
}
struct DetailView: View {
var body: some View {
List {
NavigationLink(destination: Text("Detail Title")) {
Text("New View")
}
}
.navigationBarItems(trailing:
Button(action: {
print("Clicked")
}) {
Image(systemName: "square.and.arrow.up")
})
}
}
问题出在我使用的设备上。
在iPhone上运行时,我会看到OP发布的消息。
在iPad上运行时,我不会看到任何消息。
现在,为什么要这样做?
对于初学者来说,您可以在此Apple reference中查找断言所引用的displayModeButtonItem
。
或者,查看上面代码的屏幕截图。
iPhone:
iPad:
请注意iPad如何显示displayModeButtonItem
的图标,而iPhone则没有。
基于此,我认为苹果犯了一个错误。也许它将在下一个版本中得到修复?
您能做的最好的事就是to file a bug。
FWIW,我确实查看了release notes,但找不到对此的任何引用。
,将我的 iOS 13 应用更新到 iOS 14 后,我看到此错误并且我的导航栏无法正常工作。
要修复此错误,我只需进行一项更改:
NavigationView{
// other code
}
.navigationViewStyle(StackNavigationViewStyle())
,
当我在iPhone或iPhone模拟器上运行但不在iPad模拟器上运行时,我正在Xcode 12.1上获取此信息。
将其附加到NavigationView中为我修复了该问题。
.navigationViewStyle(StackNavigationViewStyle())
,
将max
附加到NavigationView确实可以使错误静音。
不幸的是,这并不总是理想的解决方案,有时可能会引入另一个特定于function subscriptiton() {
let name = prompt("What is your name?");
let email = prompt("What is your email address?");
if (isNaN(email)) {
alert(
"Thank you " +
name +
"! We will be in touch via email,meanwhile remember bees are our friends!"
);
} else {
alert("Please enter valid email address.?");
}
}
的现有错误,其中包括:REST parameter。