简体   繁体   English

iOS15 - 如果新视图的出现更新 ObservedObject,则第一个 NavigationLink 不起作用

[英]iOS15 - First NavigationLink doesn't work if onAppear of new view updates ObservedObject

This is a really weird issue that I haven't been able to resolve.这是一个非常奇怪的问题,我一直无法解决。

It happens only on iOS 15 and only the 1st time I try to open this specific NavigationLink.它仅在 iOS 15 上发生,并且仅在我第一次尝试打开此特定 NavigationLink 时发生。

I have 3 SwiftUI Views:我有 3 个 SwiftUI 视图:

  • ContentView (entry point) ContentView(入口点)
  • DetailView详细视图
  • ItemView项目视图

ContentView is a list of DetailViews and in detail views there can be any amount if ItemViews. ContentView 是一个 DetailViews 列表,在详细视图中,如果 ItemViews.

I have an ObservableObject with a Published property count , that is only accessed from ContentView.我有一个 ObservableObject,其Published属性count只能从 ContentView 访问。 In ItemView I have function that's triggered by onAppear , that updates count in the ObservedObject.在 ItemView 中,我有一个由onAppear触发的onAppear ,它更新 ObservedObject 中的count

When I open an ItemView for the first time after opening the App, it moves to the view but immediately goes back to DetailView.当我在打开应用程序后第一次打开 ItemView 时,它移动到视图但立即返回到 DetailView。 It doesn't happen, when I open it again, even though count is updated again.它不会发生,当我再次打开它时,即使count再次更新。

I have spent a lot of time debugging this issue, but I'm out of ideas.我花了很多时间调试这个问题,但我没有想法。 I have tried reproducing it in a Swift Playground, but everything I've tried there seems to work as expected.我曾尝试在 Swift Playground 中重现它,但我在那里尝试过的一切似乎都按预期工作。

I hope someone has an idea on how I can resolve this issue, I would be most grateful!我希望有人知道我如何解决这个问题,我将不胜感激!

If you are using a nav link, I would highly suggest using a custom one instead.如果您使用的是导航链接,我强烈建议您改用自定义链接。 I can't understand why this is only happening in ios 15 for you, but I have had a similar bugs with the same views/logic in previous OS versions.我不明白为什么这只会在 ios 15 中发生,但我在以前的操作系统版本中遇到了具有相同视图/逻辑的类似错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SwiftUI 不会在嵌套 NavigationLink 目标中使用 ObservedObject 更新 UI - SwiftUI doesn't update UI with ObservedObject in nested NavigationLink destination SwiftUI 3.0 iOS15 调整 View up with Keyboard show - Adjust View up with Keyboard show in SwiftUI 3.0 iOS15 如果父对象有更新,则 ObservedObject 无法处理 NavigationLink 的目标 - ObservedObject not working on NavigationLink's destination if there are updates on parent 切换 iCloud 同步 iOS15 / SwiftUI - Toggle iCloud Sync iOS15 / SwiftUI iOS15 UITextView 拖动视图后,导致崩溃,无效参数不满足:pos - iOS15 UITextView After dragging the view, it causes a crash, Invalid parameter not satisfying: pos NavigationLink、isActive 在 SwiftUI 中不起作用 - NavigationLink, isActive doesn´t work in SwiftUI SwiftUI NavigationLink push in onAppear 使用@ObservableObject 时立即弹出视图 - SwiftUI NavigationLink push in onAppear immediately pops the view when using @ObservableObject 将 ios13.1 升级到 13.2 的问题 - NavigationLink - 试图弹出一个不存在的视图 controller - Issues upgrading ios13.1 to 13.2 - NavigationLink - tried to pop to a view controller that doesn't exist 使滚动条在 iOS 15 上始终可见不起作用 - Make scrollbar always visible on iOS 15 doesn't work 我正在使用 NavigationLink 在视图之间导航,但它在 SwiftUI 的单个视图中不起作用 - I am using NavigationLink to navigate between views and it doesn't work in a single view in SwiftUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM