2

出于某种原因,我的 NavigationLink 似乎只能在长按时工作。这是视图的片段:

struct MainView: View {
    @EnvironmentObject var user: UserObservable
    var body: some View {
        VStack {
            NavigationView {
                List(user.items, id: \.self) { item in
                    NavigationLink(destination: ItemView(item: item)) {
                        Text(item.name)
                    }
                }
                .navigationBarTitle("\(user.displayName)'s items")
                .navigationBarItems(leading: AddItemViewButton().environmentObject(user),
                                    trailing: MainViewActionSheet().environmentObject(user))
            }
        }
    }
}

该列表已正确填充,但点击它们没有任何作用。按住然后松开确实会打开正确的目的地。

有没有其他人见过这样的事情?这是在 Xcode 11.4.1 和 iOS 13.4.1 上。

4

2 回答 2

5

感谢所有提供帮助的人,事实证明我的问题是我onTapGesture在我SceneDelegate的键盘上留下了一个应该在打字时关闭键盘但我NavigationLink的 s 无法打开的东西。哎呀。

如果有人也遇到这个问题,它看起来有点像这样:

// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = UIHostingController(rootView: ContentView()
        .environmentObject(user)
        .onTapGesture { window.endEditing(true) }) // <- Problem right there
    self.window = window
    window.makeKeyAndVisible()
}
于 2020-04-17T05:12:33.000 回答
0

在我的情况下,我的自定义视图也有一个 onTapGesture。删除手势后,问题得到解决。

  CarouselContentView(data: eachItem)
        .frame( height: 200, alignment: .center).onTapGesture {   
        } <== Removed it
于 2020-12-25T12:18:19.690 回答