SwiftUI - 表单中的 NavigationLink 单元格在详细信息弹出后保持突出显示 [英] SwiftUI - NavigationLink cell in a Form stays highlighted after detail pop

查看:15
本文介绍了SwiftUI - 表单中的 NavigationLink 单元格在详细信息弹出后保持突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS 14 中,在 Form 上下文中返回后,NavigationLink 似乎不会被取消选择.这对于 Form Picker 和其他任何导致从列表中呈现另一个 View 的东西也是如此(为呈现的内容提供突出显示的上下文)单元格).

In iOS 14, it appears that NavigationLinks do not become deselected after returning in a Form context. This is also true for Form Pickers and anything else that causes the presentation of another View from a list (giving a highlight context to the presenting cell).

我在 iOS 13 中没有注意到这种行为.

I didn't notice this behaviour in iOS 13.

有没有办法在其他视图被关闭后取消选择"突出显示的行?

Is there a way to 'deselect' the highlighted row once the other view is dismissed?

示例代码:

struct ContentView: View {

    var body: some View {
        Form {
            NavigationLink(destination: Text("Detail")) {
                Text("Link")
            } 
        }
    }

}

(不同的)示例视觉:

推荐答案

在我的例子中,当在我的 NavigationViewList/Form.

In my case this behaviour appeared when using any Viewcontent (e.g. Text(), Image(), ...) between my NavigationView and 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")
                }
            }
        }
    }
}

将 Text() 置于列表之下不会产生任何问题:

Putting the Text() beneath the List does not make any problems:

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 的错误.随着更多人报告此问题,它会越早得到解决.

This is definitely a XCode 12 bug. As more people report this, as earlier it gets resolved.

这篇关于SwiftUI - 表单中的 NavigationLink 单元格在详细信息弹出后保持突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆