SwiftUI:如果不在列表中,NavigationLink 将无法工作 [英] SwiftUI: NavigationLink not working if not in a List
问题描述
我猜这可能是 beta 3 中的一个错误,因为 NavigationView 已全部损坏.但是这样的观点:
I guess it might be a bug in beta 3 as the NavigationView is all broken. But a view like that:
struct GenreBadge : View {
@EnvironmentObject var store: Store<AppState>
let genre: Genre
var body: some View {
NavigationLink(destination: MoviesGenreList(genre: genre).environmentObject(store)) {
RoundedBadge(text: genre.name)
}
}
}
不会触发导航堆栈中的任何推送.该视图似乎根本没有交互性.如果有人找到解决方法会很好,除非 Apple 记录此行为,否则我会认为它在测试版 4 之前已损坏.
is not triggering any push in the navigation stack. The view doens't seems interactive at all. If anyone found a workaround would be good, unless Apple is documenting this behaviour I would consider it broken until beta 4.
推荐答案
我已向 Apple 报告了 Xcode 11.3(11C29) 版中的导航链接似乎存在错误.
There seems to be a bug with the navigation link in Xcode version 11.3(11C29) which I have reported to Apple.
注意:这个问题只出现在模拟器中.它在真实设备上运行良好.感谢@djr
以下代码在您第一次使用导航链接时按预期工作.不幸的是,它第二次变得没有反应.
The below code works as expect the first time you use the navigation link. Unfortunately it becomes unresponsive the second time around.
import SwiftUI
struct ContentView : View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: SomeView()) {
Text("Hello!")
}
}
}
}
}
struct SomeView: View {
var body: some View {
Text("Detailed View")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
这篇关于SwiftUI:如果不在列表中,NavigationLink 将无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!