[英]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 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.