macOS 上的 NavigationLink 未在同一视图中打开 [英] NavigationLink on macOS not opening in the same View

查看:32
本文介绍了macOS 上的 NavigationLink 未在同一视图中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 SwiftUI(无催化剂)构建一个 macOS 应用程序,它应该有一个侧边栏和一个右侧的视图.

I'm currently building a macOS App with SwiftUI (no Catalyst) that is supposed to have a Sidebar and a single View to the right of it.

NavigationView {
    List {
        ...
    }
    .listStyle(SidebarListStyle())

    HomeView()
}

我的主页视图内部有一个 NavigationLink,指向另一个 DetailView.

My Home View has a NavigationLink inside of it, pointing to another DetailView.

struct HomeView: View {
    var body: some View {
        NavigationLink("DetailView", destination: Text("This is the DV"))
    }
}

此 NavigationLink 始终显示为禁用状态,并且仅在我向 NavigationView 添加另一列时才有效.我不想要另一个列,而是 NavigationLink 替换 HomeViewDetailView.

This NavigationLink always appears as disabled and only works when I add another Column to the NavigationView. I don't want another Column, but rather the NavigationLink replacing the HomeView with the DetailView.

有什么办法可以做到这一点吗?

Is there any way to achieve this?

推荐答案

显然 SwiftUI 2 还不支持将视图推送到 macOS 上的导航堆栈.但是,我发现这个包有助于解决这个问题:

So apparently SwiftUI 2 does not support pushing views on to the Navigation Stack on macOS yet. However, I found this package that helps to resolve the issue:

github.com/lbrndnr/StackNavigationView

这篇关于macOS 上的 NavigationLink 未在同一视图中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆