【问题标题】:SwiftUI navigation bar missing in Xcode 14.0 beta 2 (14A5229c)Xcode 14.0 beta 2 (14A5229c) 中缺少 SwiftUI 导航栏
【发布时间】:2022-08-08 22:28:19
【问题描述】:

我假设我可能应该将此作为反馈报告提交给 Apple,但在此处发布以防我遗漏了什么 - 或者如果有最新 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
        }
    }
}

    标签: xcode swiftui beta


    【解决方案1】:

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


    似乎他们优化了工具栏的构造(并且不要假设它已更改)。无论如何,我现在只看到一种解决方法:

        NavigationView {
    
        // .. content
    
        }
        .id(isFlowDetermined)  // << here !!
    

    使用 Xcode 14b2 / iOS 16 测试

    *注意:NavigationView 自 iOS 16 起已弃用

    【讨论】:

    • 好的。谢谢。会提交错误报告。了解 NavigationView 已弃用,但不能真正放弃 iOS 15。
    • 反馈报告:FB10484666
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多