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

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

问题描述

我正在开发一个具有登录功能的应用程序,登录后会列出类别.在每个类别下都有一些水平列出的项目.事情是登录后,主页面出现,一切都列出来了.当您单击一个项目时,它会进入详细屏幕,但是当您尝试返回时,它就会崩溃.我发现了这个流程 为什么在NavigationView"中的navigationBarItems"内放置NavigationLink"后,我的 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.

推荐答案

[UPDATE] Nov 5, 2020 - pawello2222表示此问题已在 Xcode 12.1 中修复.

[UPDATE] Nov 5, 2020 - pawello2222 says that this issue has been fixed in Xcode 12.1.

[UPDATE] 2020 年 6 月 14 日 - Quang Hà 说这个问题又回来了在 Xcode 11.5 中.

[UPDATE] Jun 14, 2020 - Quang Hà says that this issue has come back in Xcode 11.5.

[更新] 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 的错误.

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天全站免登陆