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

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

问题描述

在iOS 14中,在 Form 上下文中返回后,似乎未取消选择 NavigationLink s.对于 Form Picker s以及导致列表中另一个 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")
            } 
        }
    }

}

(不同)示例示例:

推荐答案

在我的情况下,当在我的 NavigationView 之间使用任何Viewcontent(例如Text(),Image(),...)时,就会出现此行为>和 List/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天全站免登陆