[英]NavigationLink on macOS causing source view to appear twice
macOS
when using NavigationLink
, the source view is appearing twice.macOS
上使用NavigationLink
时,源视图会出现两次。macOS
(see print
statements)macOS
上(见print
语句)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.