Xcode 14.0 Beta 2(14A5229C)中缺少Swiftui导航栏

发布于 2025-02-11 03:55:10 字数 1598 浏览 1 评论 0原文

我假设我可能应该将此作为反馈报告,但在此处发布,以防万一我缺少某些内容 - 或者如果有最新的Swiftui有新的指导。

该代码在Xcode 13中的预期工作,但是在Xcode 14 Beta 2中,导航栏和“取消”按钮丢失了。此progressview带有延期内容加载的一种不再起作用的技术吗?

import SwiftUI

struct ContentView: View {
    
    @State private var isFlowDetermined = false
    
    var body: some View {

        NavigationView {
            
            //NestedView()
            
            if self.isFlowDetermined {
                NestedView()
            } else {
                ProgressView()
                    .task {
                        await self.determineFlow()
                    }
            }
        }
    }
    
    private func determineFlow() async {
        
        self.isFlowDetermined = true
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct NestedView: View {
    
    var body: some View {
        
        ScrollView {
            Text("Where is the \"Cancel\" button?")
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(Color.green)
    #if !os(macOS)
        .navigationBarTitleDisplayMode(.inline)
    #endif
        .toolbar {
    #if !os(macOS)
            ToolbarItem(placement: .navigationBarLeading) {
                Button("Cancel") {
                    print("got here")
                }
            }
    #endif
        }
    }
}

I'm assuming I should probably file this as a feedback report with Apple, but posting here in case I am missing something - or if there is new guidance with latest SwiftUI.

This code works as expected in Xcode 13, but in Xcode 14 beta 2, the navigation bar and "Cancel" button are missing. Is this ProgressView with deferred content loading somehow a technique that doesn't work anymore?

import SwiftUI

struct ContentView: View {
    
    @State private var isFlowDetermined = false
    
    var body: some View {

        NavigationView {
            
            //NestedView()
            
            if self.isFlowDetermined {
                NestedView()
            } else {
                ProgressView()
                    .task {
                        await self.determineFlow()
                    }
            }
        }
    }
    
    private func determineFlow() async {
        
        self.isFlowDetermined = true
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct NestedView: View {
    
    var body: some View {
        
        ScrollView {
            Text("Where is the \"Cancel\" button?")
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(Color.green)
    #if !os(macOS)
        .navigationBarTitleDisplayMode(.inline)
    #endif
        .toolbar {
    #if !os(macOS)
            ToolbarItem(placement: .navigationBarLeading) {
                Button("Cancel") {
                    print("got here")
                }
            }
    #endif
        }
    }
}

Navigation bar area with no "Cancel" button or navigation bar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-18 03:55:10

更新:Xcode 14 beta 4似乎可以解决此问题。下面建议的解决方法不再需要。


似乎他们优化了工具栏的构建(并且不要以为它已更改)。无论如何,我目前只看到一个解决方法:

    NavigationView {

    // .. content

    }
    .id(isFlowDetermined)  // << here !!

用Xcode 14B2 / ios 16

*注意:navigationView < / code>自ios 16以来已被弃用

UPDATE: Xcode 14 beta 4 appears to resolve this issue. The suggested workaround below is no longer needed.


It seems they optimised toolbar construction (and don't assume it is changed). Anyway I see only one workaround for now:

    NavigationView {

    // .. content

    }
    .id(isFlowDetermined)  // << here !!

Tested with Xcode 14b2 / iOS 16

*Note: NavigationView is deprecated since iOS 16

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文