如何在SwiftUI中在没有NavigationButton的情况下导航到NavigationView中的另一个视图? [英] How to navigate to another view in NavigationView without NavigationButton in SwiftUI?

查看:45
本文介绍了如何在SwiftUI中在没有NavigationButton的情况下导航到NavigationView中的另一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如问题所述,我想在不使用NavigationButton的情况下导航到另一个视图,例如UIkit中的"pushView"和"popView"

As the questions says I want to navigate to another view without NavigationButton, something like "pushView" and "popView" in UIkit

推荐答案

我认为这更像是一种限制的解决方法,但它对我有用:

I consider this more like a work-around for a limitation, but it worked for me:

添加一个布尔状态变量,该变量定义链接是否处于活动状态.例如:

Add a boolean state variable which defines whether the link is active. E.g.:

@State private var showLinkTarget = false

添加一个不可见的NavigationLink,如下所示:

Add an invisible NavigationLink like this:

NavigationLink(destination: LinkTargetView(), isActive: self.$showLinkTarget ) {
   Spacer().fixedSize() 
}

这篇关于如何在SwiftUI中在没有NavigationButton的情况下导航到NavigationView中的另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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