For some reason it seems that my NavigationLink is only working on long press. Here's a snippet of the View:
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))
}
}
}
}
The list is populated correctly but tapping on them does nothing. Pressing and holding and then releasing does open the correct destination.
Has anyone else seen anything like this? This is on Xcode 11.4.1 and iOS 13.4.1.
Thanks to all who helped, it turns out my issue was I had left an onTapGesture
in my SceneDelegate
that was supposed to close the keyboard when typing but instead kept my NavigationLink
s from opening. Oops.
It looked a bit like this in case anyone runs into this issue too:
// 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()
}
In my case also, my custom view had an onTapGesture. On removing the gesture, the issue got resolved.
CarouselContentView(data: eachItem)
.frame( height: 200, alignment: .center).onTapGesture {
} <== Removed it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With