NavigationLink只工作一次 [英] NavigationLink Works Only for Once

查看:245
本文介绍了NavigationLink只工作一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理具有登录名的应用程序,登录后列出了类别.在每个类别下,都有一些水平列出的项目.事情是登录后,出现主页,所有内容都列出了.当您单击某个项目时,它将转到详细屏幕,但是当您尝试返回时,它就会崩溃.我发现此流程为什么在将`NavigationLink`放入`NavigationView`中的`navigationBarItems`中后向后导航时,我的SwiftUI应用程序崩溃了,但是我无法解决我的问题.由于我的项目变得复杂,所以我只想在swiftui中练习导航,然后创建了一个新项目.顺便说一下,我下载了最新的xcode版本11.3.我编写了一个简单的代码,如下所示:

I was working on an application with login and after login there are categories listed. And under each category there are some items listed horizontally. The thing is after login, main page appears and everything is listed great. When you click on an item it goes to detailed screen but when you try to go back it just crashes. I found this flow Why does my SwiftUI app crash when navigating backwards after placing a `NavigationLink` inside of a `navigationBarItems` in a `NavigationView`? but i could not solve my problem. Since my project become complicated, I just wanted to practice navigation in swiftui and I created a new project. By the way I downloaded the latest xcode version 11.3. I wrote a simple code as follows:

NavigationView{
        NavigationLink(destination: Test()) {
            Text("Show Detail View")
        }
    .navigationBarTitle("title1")

Test()视图如下:

And Test() view is as follows:

import SwiftUI

struct Test: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct Test_Previews: PreviewProvider {
    static var previews: some View {
        Test()
    }
}

如您所见,这确实很简单.我还在互联网上尝试过类似的示例,但是它不能像预期的那样工作.运行项目时,单击导航链接,然后导航到Test()视图.然后,我单击后退"按钮,它导航到主页.但是,当我第二次单击导航链接时,没有任何反应.导航链接仅工作一次,此后什么也没有发生.它不会导航,它不会抛出任何错误.我是swiftui的新手,除了导航之外,其他所有方面都很出色.我在互联网上尝试了许多示例并提出了解决方案,但似乎没有什么可以解决我的问题.

As you can see it is really simple. I also tried similar examples on the internet but it does not work the way it suppose to work. When I run the project, I click the navigation link and it navigates to Test() view. Then I click back button and it navigates to the main page. However, when I click the navigation link second time, nothing happens. Navigation link works only once and after that nothing happens. It does not navigate, it des not throw any error. I am new to swiftui and everything is great but the navigation. I tried many examples and suggested solutions on the internet, but nothing seems to fix my issues.

推荐答案

[更新] 2020年2月12日-我在Xcode 11.4 beta中检查了此问题,发现此问题已解决.

[UPDATE] Feb 12, 2020 - I checked for this issue in Xcode 11.4 beta and found that this issue has been resolved.

当我在Xcode的模拟器中进行测试时,我的项目中也遇到了同样的问题.但是,当我在真实设备(带有iOS 13.3的iPhone X)上启动该应用程序时,NavigationLink可以正常工作.因此,它的确确实像Xcode的bug.

I was getting the same issue in my project too, when I was testing it in Xcode's simulator. However, when I launched the app on a real device (iPhone X with iOS 13.3), NavigationLink was working totally fine. So, it really does seem like Xcode's bug.

这篇关于NavigationLink只工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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