简体   繁体   English

macOS 上的 NavigationLink 导致源视图出现两次

[英]NavigationLink on macOS causing source view to appear twice

Overview:概述:

  • On macOS when using NavigationLink , the source view is appearing twice.macOS上使用NavigationLink时,源视图会出现两次。
  • It only happens on macOS (see print statements)它只发生在macOS上(见print语句)

Questions:问题:

  • How to resolve this?如何解决这个问题?
  • Is there a workaround?有解决方法吗?

Code:代码:

import SwiftUI

struct ContentView: View {
    
    let names = ["aaa"]
    
    var body: some View {
        NavigationView {
            List {
                ForEach(names, id: \.self) { name in
                    NavigationLink(destination: Text("dest")) {
                        Text(name)
                            .onAppear {
                                print("\(name) appeared")
                            }
                    }
                }
            }
        }
    }
}

To resolve this, simply "attach" the .onAppear to your NavigationLink not the Text .要解决此问题,只需将.onAppear “附加”到您的NavigationLink而不是Text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM