在iOS 14中,在Form上下文中返回后,NavigationLink似乎没有被取消选择。这也适用于Form Picker以及任何其他导致显示列表中的另一个View的内容(为显示的单元格提供突出显示上下文)。
我在iOS 13中没有注意到这个行为。
有没有一种方法可以在另一个视图关闭后取消选择突出显示的行?
示例代码:
struct ContentView: View {
var body: some View {
Form {
NavigationLink(destination: Text("Detail")) {
Text("Link")
}
}
}
}(不同)视觉示例:

发布于 2020-09-22 01:37:59
在我的例子中,当使用任何视图内容(例如Text(),Image(),...)时,会出现这种行为。在我的NavigationView和List/Form之间。
var body: some View {
NavigationView {
VStack {
Text("This text DOES make problems.")
List {
NavigationLink(destination: Text("Doesn't work correct")) {
Text("Doesn't work correct")
}
}
}
}
}将文本()放在列表的下面不会产生任何问题:
var body: some View {
NavigationView {
VStack {
List {
NavigationLink(destination: Text("Does work correct")) {
Text("Does work correct")
}
}
Text("This text doesn't make problems.")
}
}
}这绝对是一个XCode 12错误。随着更多的人报告这个问题,它得到了更早的解决。
发布于 2021-02-14 00:46:42
我也遇到过这个问题,我相信我找到了问题的根本原因。
在我的例子中,我有一个类似如下的结构:
struct Page1View: View {
var body: some View {
NavigationView {
List {
NavigationLink("Page 2", destination: Page2View())
}
.listStyle(GroupedListStyle())
.navigationBarTitle("Page 1")
}
}
}
struct Page2View: View {
var body: some View {
List {
NavigationLink("Page 3", destination: Text("Page 3"))
}
.listStyle(GroupedListStyle())
.navigationBarTitle("Page 2")
}
}在指向第3页的NavigationLink上会出现此问题。在控制台输出中,使用该链接时会显示此错误:
2021-02-13 16:41:00.599844+0000 App[59157:254215] [Assert] displayModeButtonItem is internally managed and not exposed for DoubleColumn style. Returning an empty, disconnected UIBarButtonItem to fulfill the non-null contract.我发现我需要在NavigationView上应用.navigationViewStyle(StackNavigationViewStyle()),这就解决了问题。
也就是说。
struct Page1View: View {
var body: some View {
NavigationView {
List {
NavigationLink("Page 2", destination: Page2View())
}
.listStyle(GroupedListStyle())
.navigationBarTitle("Page 1")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}发布于 2021-04-27 19:27:11
今天我已经和这个问题斗争了半天,并来到了这篇文章,这篇文章帮助我理解了如果Text、Button或其他东西放在NavigationView和我的List之间,就会出现这个问题。我找到了适合我的解决方案。只需为项目添加.zIndex()即可。.zIndex()必须高于使用Xcode 12.5尝试的List。
var body: some View {
NavigationView {
VStack {
Text("This text DOES make problems.")
.zIndex(1.0)
List {
NavigationLink(destination: Text("Doesn't work correct")) {
Text("Doesn't work correct")
}
}
}
}
}https://stackoverflow.com/questions/63934037
复制相似问题