【问题标题】:Swift Navigation Link problemsSwift 导航链接问题
【发布时间】:2020-09-25 08:18:32
【问题描述】:

我在 Swift 和 iOS 14 中遇到了 NavigationLink 的问题。这是一个已知问题,但是我看到的问题解决者还不够。我发现当一个带有NavigationLink 的按钮被提前初始化时,它可以工作,当你进入页面时,你有“返回”按钮。但是,当导航链接在中间时,进入页面后无法返回,必须关闭应用才能再次进入主屏幕。

这是我正在使用的代码:

HStack {
    Button(action: {
        if let url = URL(string: "I blacked this out to make no advert here") {
            UIApplication.shared.open(url)
        }
    }){
        Text("Rate App").foregroundColor(.gray)
    }.modifier(navigationButtonViewStyle())
    
    Spacer()
    // this navigation link works fine
    NavigationLink(destination: HelpView()) {
        Text("FAQ").foregroundColor(.gray)
    }.modifier(navigationButtonViewStyle())
}.padding(.horizontal, 20)

VStack {
    Text("λSET")
    .font(.largeTitle)
    .fontWeight(.heavy)
    .bold()
    .padding(.top, 50)
    .onAppear(perform: prepareHaptics)
    .animation(.linear)
    
    Text("λudio System Engineer Tools")
    .fontWeight(.light)
    .animation(.linear(duration: 0.5))
    
    HStack {
        
        Spacer()
        
        // this navigation link is not showing the go back button when pressed and directed to the new screen
        NavigationLink(destination: AboutView()) {
            Text("About λSET")
            .fontWeight(.heavy)
            .bold()
        }
        
        
        Spacer()
        
    }.modifier(calcTitleViewStyle())
    .padding(.top, 20)
    .padding(.bottom, 60)
}

我不确定问题是什么,但很好奇这可能是什么。我正在研究一种解决方法,但我很想从根本上解决问题。

谢谢!

【问题讨论】:

    标签: swift swiftui swiftui-navigationlink


    【解决方案1】:

    通过将 .NavigationBar 显式设置为 true 以强制 swift 加载它,我自己修复了它。这在其他页面中不需要,但我现在正在确保 IOS14 接受它,因为那里已经更改了一些内容。

    【讨论】:

      猜你喜欢
      • 2023-02-06
      • 2020-10-18
      • 2021-12-28
      • 2019-05-27
      • 2017-07-08
      • 2021-08-03
      • 2020-04-09
      • 2021-02-13
      • 1970-01-01
      相关资源
      最近更新 更多